#include<bits/stdc++.h>
using namespace std;
using ll=long long;
static const ll mod=1000000007;
ll H,W;
char a[2005][2005];
ll dp[2005][2005];
ll sumx[2005][2005];
ll sumy[2005][2005];
ll sumxy[2005][2005];
int main(){
cin>>H>>W;
  for(ll i=0;i<H;i++){
  string s;cin>>s;
    for(ll j=0;j<W;j++)
      a[i][j]=s[j];
  }dp[1][1]=1;sumx[1][1]=1;sumy[1][1]=1;sumxy[1][1]=1;
  for(ll i=1;i<=H;i++)
    for(ll j=1;j<=W;j++)
      if(a[i-1][j-1]!='#'){
      dp[i][j]=(dp[i][j]+sumx[i-1][j])%mod;
       dp[i][j]=(dp[i][j]+sumy[i][j-1])%mod;
      dp[i][j]=(dp[i][j]+sumxy[i-1][j-1])%mod;
        sumx[i][j]=(sumx[i-1][j]+dp[i][j])%mod;
          sumy[i][j]=(sumy[i][j-1]+dp[i][j])%mod;
          sumxy[i][j]=(sumxy[i-1][j-1]+dp[i][j])%mod;
      }cout<<dp[H][W]<<endl;
  return 0;
}
#include <iostream>
#include <cstdio>
#include <vector>

using namespace std;

typedef long long ll;

ll n, m;
bool v[1005][1005];
ll cp[2005];
bool v1[2005], v2[2005];
ll cnt1, cnt2;

ll fnd(ll p)
{
    if(cp[p] == p) return p;
    return cp[p] = fnd(cp[p]);
}

void uni(ll p, ll q)
{
    if(fnd(p) == fnd(q)) return;
    cp[fnd(p)] = fnd(q);
}

int main()
{
    scanf("%lld%lld", &n, &m);
    for(ll i = 0; i < n + m; i++) cp[i] = i;
    for(ll i = 0; i < n; i++)
    {
        string s;
        cin>>s;
        for(ll j = 0; j < m; j++)
        {
            if(s[j] == '#') v[i][j] = true, uni(i, j + n);
        }
    }
    uni(0, n - 1);
    uni(0, n);
    uni(0, m + n - 1);
    for(ll i = 0; i < n; i++)
    {
        if(!v1[fnd(i)]) cnt1++, v1[fnd(i)] = true;
    }
    for(ll i = 0; i < m; i++)
    {
        if(!v2[fnd(i + n)]) cnt2++, v2[fnd(i + n)] = true;
    }
    printf("%lld\n", min(cnt1 - 1, cnt2 - 1));
    return 0;
}
