#include <bits/stdc++.h>

const int N = 2010;
const int INF = 0x3f3f3f3f;
const long long mod = 1e9 + 7;

int t;
int n, m;
char a[N][N];
long long dp[N][N];
long long pre[N][N][3]; // 0: left 1: up 2: diagonal

int main() {

  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; ++i) {
    scanf("%s", a[i] + 1);
  }
  dp[1][1] = 1ll;
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= m; ++j) {
      if (a[i][j] == '#') {
        continue;
      }
      if (i - 1 >= 1 && j - 1 >= 1 && a[i][j] != '#') {
        dp[i][j] = (dp[i][j] + pre[i - 1][j - 1][2]) % mod;
      }
      if (i - 1 >= 1 && a[i - 1][j] != '#') {
        dp[i][j] = (dp[i][j] + pre[i - 1][j][1]) % mod;
      }
      if (j - 1 >= 1 && a[i][j - 1] != '#') {
        dp[i][j] = (dp[i][j] + pre[i][j - 1][0]) % mod;
      }

      if (i - 1 >= 1 && j - 1 >= 1 && a[i][j] != '#') {
        pre[i][j][2] = (pre[i - 1][j - 1][2] + dp[i][j]) % mod;
      } else {
        pre[i][j][2] = dp[i][j];
      }
      if (i - 1 >= 1 && a[i - 1][j] != '#') {
        pre[i][j][1] = (pre[i - 1][j][1] + dp[i][j]) % mod;
      } else {
        pre[i][j][1] = dp[i][j];
      }
      if (j - 1 >= 1 && a[i][j - 1] != '#') {
        pre[i][j][0] = (pre[i][j - 1][0] + dp[i][j]) % mod;
      } else {
        pre[i][j][0] = dp[i][j];
      }
    }
  }
  printf("%lld\n", dp[n][m]);
  return 0;
}
#include <bits/stdc++.h>

using namespace std;

const int inf = numeric_limits<int> :: max() / 2;

class dsu {
    private:
    vector<int> par;

    public:
    dsu(int N) : par(N) {
        iota(par.begin(), par.end(), 0);
    }

    int find(int x) {
        return x == par[x] ? x : par[x] = find(par[x]);
    }

    bool same(int x, int y) {
        return find(x) == find(y);
    }

    void Union(int x, int y) {
        if(same(x, y)) {
            return;
        }
 
        x = find(x);
        y = find(y);
        par[x] = y;
    }
};

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int n, m;
    cin >> n >> m;

    vector<string> s(n);
    for (int i = 0; i < n; ++i) {
        cin >> s[i];
    }

    vector<bool> row(n);
    vector<bool> col(m);
    row[0] = row[n - 1] = true;
    col[0] = col[m - 1] = true;
    for (int i = 0; i < n; ++i) {
        if (s[i][0] == '#' || s[i][m - 1] == '#') {
            row[i] = true;
        } 
    }
    for (int i = 0; i < m; ++i) {
        if (s[0][i] == '#' || s[n - 1][i] == '#') {
            col[i] = true;
        }
    }

    int ans = inf;

    dsu dsu(n + m);

    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < m; ++j) {
            if (s[i][j] == '#') {
                dsu.Union(i, j + n);
            }
        }
    }

    dsu.Union(0, n - 1);
    dsu.Union(n, n + m - 1);
    dsu.Union(n - 1, n);

    int tc = 0;
    for (int i = 0; i < m; ++i) {
        bool same = false;
        for (int j = i + 1; j < m; ++j) {
            if (dsu.same(i + n, j + n)) {
                same = true;
            }
        }
        if (!same) {
            tc ++;
        }
    }

    int tr = 0;
    for (int i = 0; i < n; ++i) {
        bool same = false;
        for (int j = i + 1; j < n; ++j) {
            if (dsu.same(i, j)) {
                same = true;
            }
        }
        if (!same) {
            tr ++;
        }
    }

    cout << min(tr, tc) - 1 << '\n';

    return 0;
}
