Amber Claes Maes, a patissier, opened her own shop last month. She decided to submit her work to the International Chocolate Patissier Competition to promote her shop, and she was pursuing a recipe of sweet chocolate bars. After thousands of trials, she finally reached the recipe. However, the recipe required high skill levels to form chocolate to an orderly rectangular shape. Sadly, she has just made another strange-shaped chocolate bar as shown in Figure G-1.
Figure G-1: A strange-shaped chocolate bar
Each chocolate bar consists of many small rectangular segments of chocolate. Adjacent segments are separated with a groove in between them for ease of snapping. She planned to cut the strange-shaped chocolate bars into several rectangular pieces and sell them in her shop. She wants to cut each chocolate bar as follows.
Figure G-2: An instance of cutting that follows the rules
Figure G-3: An instance of cutting that leaves a non-rectangular piece
Figure G-4: An instance of cutting that yields more pieces than Figure G-2
Your job is to write a program that computes the number of pieces of chocolate after cutting according to the rules.
The input is a sequence of datasets. The end of the input is indicated by a line containing two zeros separated by a space. Each dataset is formatted as follows.
h wThe integers h and w are the lengths of the two orthogonal dimensions of the chocolate, in number of segments. You may assume that 2 ≤ h ≤ 100 and 2 ≤ w ≤ 100. Each of the following h lines consists of w characters, each is either a "
r(1, 1) ... r(1, w)
r(2, 1) ... r(2, w)
...
r(h, 1) ... r(h, w)
Figure G-5: Disconnected chocolate bars
Figure G-6: A chocolate bar with a hole
Figure G-7: Another instance of a chocolate bar with a hole
For each dataset, output a line containing the integer representing the number of chocolate pieces obtained by cutting according to the rules. No other characters are allowed in the output.
3 5 ###.# ##### ###.. 4 5 .#.## .#### ####. ##.#. 8 8 .#.#.#.# ######## .######. ######## .######. ######## .######. ######## 8 8 .#.#.#.# ######## .##.#.#. ##....## .##.###. ##...### .##.###. ###.#.## 4 4 #### #### #### #### 0 0
3 5 11 19 1