#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 10;
const int mod = 1e8 + 7;
vector<int> v[maxn];
vector<int> dp1[maxn], dp2[maxn];
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 0; i <= n + 1; i++) {
    for (int j = 0; j <= m + 1; j++) {
      v[i].push_back(0);
      dp1[i].push_back(0);
      dp2[i].push_back(0);
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      char c;
      scanf(" %c", &c);
      if (c == '.') v[i][j] = 1;
    }
  }
  int flag = 2;
  dp1[1][1] = 1;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (i == 1 && j == 1) continue;
      if (!v[i][j]) continue;
      dp1[i][j] = (dp1[i - 1][j] + dp1[i][j - 1]) % mod;
    }
  }
  if (dp1[n][m] == 0) flag = 0;
  if (flag != 0) {
    dp2[n][m] = 1;
    for (int i = n; i >= 1; i--) {
      for (int j = m; j >= 1; j--) {
        if (i == n && j == m) continue;
        if (i == 1 && j == 1) continue;
        if (!v[i][j]) continue;
        dp2[i][j] = (dp2[i + 1][j] + dp2[i][j + 1]) % mod;
        if (1ll * dp1[i][j] * dp2[i][j] % mod == dp1[n][m]) {
          flag = 1;
        }
      }
    }
  }
  printf("%d\n", flag);
}
