*/
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#define LL __int64
int hash[2][20005];
int state[2][20005];
LL dp[2][20005];
int cnt[2];
int jz3[9];
inlineint get(ints, int pos)
{
returns/jz3[pos]%3;
}
inlineint add(ints,int pos,int flag1,intflag2)
{
returns+(flag1-s/jz3[pos]%3)*jz3[pos]+(flag2-s/jz3[pos+1]%3)*jz3[pos+1];
}
inlineint change(ints,int pos,int flag)
{
returns+(flag-s/jz3[pos]%3)*jz3[pos];
}
inlinevoid clear(intnow)
{
memset(dp[now],0,sizeof(dp[now]));
memset(hash[now],0,sizeof(hash[now]));
cnt[now]=0;
}
int can(int s,intm)
{
inti,flag,sum=0;
for(i=0;i<=m;i++)
{
flag=s%3;
s/=3;
if(flag==1)sum++;
if(flag==2)sum--;
if(sum<0)break;
}
if(sum)return 0;
elsereturn 1;
}
int main()
{
intn,m,i,j,k,u,pre,now,col,raw,news,sum,mark,right;
LL ans;
charmap[9][9];
for(jz3[0] = 1, i = 1; i < 9; i++) jz3[i] = jz3[i - 1] * 3;
while(scanf("%d%d%c",&n,&m,&map[0][0])&&(m||n))
{
for(i = 1; i <= n; i++)
{
for(j = 1; j <= m; j++)
{
scanf("%c", &map[i][j]);
}
scanf("%c",&map[0][0]);
}
if(n==1||m==1)
printf("0n");
else
{
pre = 0, now = 1; clear(now),dp[now][0] = 1, cnt[now] = 1, state[now][cnt[now]] = 0, hash[now][0] = 1;
for(i = 1; i <= n; i++)
{
for(pre = !pre, now = !now, clear(now), j = 1; j <= cnt[pre]; j++ )
{
if( (get(state[pre][j], m) == 0) &&((i==1)||state[pre][j]))
{
news=state[pre][j] * 3;
if(can(news,m))
{
state[now][++cnt[now]]=news;
hash[now][news] = 1;
dp[now][news] = dp[pre][state[pre][j]];
}
}
}
for(j = 1;j <= m;j++)
{
pre = !pre, now = !now, clear(now);
for(k = 1; k <= cnt[pre]; k++)
{
col = get(state[pre][k],j-1), raw = get(state[pre][k],j);
if(map[i][j] =='#')
{
if(!(col||raw))
{
dp[now][state[pre][k]] += dp[pre][state[pre][k]];
if(!hash[now][state[pre][k]]) state[now][++cnt[now]] = state[pre][k], hash[now][state[pre][k]] = 1;
}
}
else
{
if(!(col||raw))
{
news = add(state[pre][k], j-1, 1, 2);
if(can(news,m))
{
dp[now][news] += dp[pre][state[pre][k]];
if(!hash[now][news]) state[now][++cnt[now]] = news, hash[now][news] = 1;
}
}
elseif(col==0&&raw==1)
{
dp[now][state[pre][k]] += dp[pre][state[pre][k]];
if(!hash[now][state[pre][k]]) state[now][++cnt[now]] = state[pre][k], hash[now][state[pre][k]] = 1;
news = add(state[pre][k], j-1, 1, 0);
if(can(news,m))
{
dp[now][news] += dp[pre][state[pre][k]];
if(!hash[now][news]) state[now][++cnt[now]] = news, hash[now][news] = 1;
}
}
elseif(col==1&&raw==0)
{
dp[now][state[pre][k]] += dp[pre][state[pre][k]];
if(!hash[now][state[pre][k]]) state[now][++cnt[now]] = state[pre][k], hash[now][state[pre][k]] = 1;
news = add(state[pre][k], j-1, 0, 1);
if(can(news,m))
{
dp[now][news] += dp[pre][state[pre][k]];
if(!hash[now][news]) state[now][++cnt[now]] = news, hash[now][news] = 1;
}
}
elseif(col==0&&raw==2)
{
dp[now][state[pre][k]] += dp[pre][state[pre][k]];
if(!hash[now][state[pre][k]]) state[now][++cnt[now]] = state[pre][k], hash[now][state[pre][k]] = 1;
news = add(state[pre][k], j-1, 2, 0);
if(can(news,m))
{
dp[now][news] += dp[pre][state[pre][k]];
if(!hash[now][news]) state[now][++cnt[now]] = news, hash[now][news] = 1;
}
}
elseif(col==2&&raw==0)
{
dp[now][state[pre][k]] += dp[pre][state[pre][k]];
if(!hash[now][state[pre][k]]) state[now][++cnt[now]] = state[pre][k], hash[now][state[pre][k]] = 1;
news = add(state[pre][k], j-1, 0, 2);
if(can(news,m))
{
dp[now][news] += dp[pre][state[pre][k]];
if(!hash[now][news]) state[now][++cnt[now]] = news, hash[now][news] = 1;
}
}
elseif(col==2&&raw==1)
{
news = add(state[pre][k], j-1, 0, 0);
if(can(news,m))
{
dp[now][news] += dp[pre][state[pre][k]];
if(!hash[now][news]) state[now][++cnt[now]] = news, hash[now][news] = 1;
}
}
elseif(col==1&&raw==1)
{
sum=1;
for(u = j + 1; u <= m; u++)
{
mark = get(state[pre][k],u);//这里的参数u原本被写成j了,是我花了几个小时一个一个状态的调试出来的,之伤感!
if(mark==1)sum++;
if(mark==2)sum--;
if(!sum)break;
}
if(!sum)
{
news = add(state[pre][k], j-1, 0, 0);
news=change(news, u, 1);
if(can(news,m))
{
dp[now][news] += dp[pre][state[pre][k]];
if(!hash[now][news]) state[now][++cnt[now]] = news, hash[now][news] = 1;
}
}
}
elseif(col==2&&raw==2)
{
sum=1;
for(u = j -2; u >= 0; u--)
{
mark = get(state[pre][k],u);
if(mark==1)sum--;
if(mark==2)sum++;
if(!sum)break;
}
if(!sum)
{
news = add(state[pre][k], j-1, 0, 0);
news=change(news, u, 2);
if(can(news,m))
{
dp[now][news] += dp[pre][state[pre][k]];
if(!hash[now][news]) state[now][++cnt[now]] = news, hash[now][news] = 1;
}
}
}
}
}
}
}
ans=0,right=jz3[0]+2*jz3[m-1];
for(j = 1; j <= cnt[now]; j++)
{
if(state[now][j]==right)
ans+=dp[now][state[now][j]];
}
printf("%I64dn",ans);
}
}
return0;
}
/*
3 2
..
..
..
2 2
..
..
2 3
#..
...
3 4
....
....
....
*/