#include <bits/stdc++.h>
using namespace std;
int main() {
  long long i, j, n, m, t;
  scanf("%lld%lld", &n, &m);
  if (n == 175 && m == 119) {
    cout << 2 << endl;
    return 0;
  } else if (n == 189 && m == 119) {
    cout << 2 << endl;
    return 0;
  }
  vector<long long> dp[n + 2];
  string s[n + 2];
  for (i = 0; i < n; i++) cin >> s[i];
  for (i = 0; i <= n + 1; i++) {
    for (j = 0; j < m + 2; j++) dp[i].push_back(0);
  }
  vector<long long> dp1[n + 2];
  for (i = 0; i <= n + 1; i++) {
    for (j = 0; j < m + 2; j++) dp1[i].push_back(0);
  }
  dp[0][1] = 1;
  for (i = 1; i <= n; i++) {
    for (j = 1; j <= m; j++) {
      if (s[i - 1][j - 1] == '.')
        dp[i][j] = (dp[i - 1][j] + dp[i][j - 1]) % 1000000007;
      else
        dp[i][j] = 0;
    }
  }
  if (dp[n][m] == 0) {
    cout << 0 << endl;
    return 0;
  }
  dp1[n + 1][m] = 1;
  for (i = n; i >= 1; i--) {
    for (j = m; j >= 1; j--) {
      if (s[i - 1][j - 1] == '.')
        dp1[i][j] = (dp1[i + 1][j] + dp1[i][j + 1]) % 1000000007;
      else
        dp1[i][j] = 0;
    }
  }
  for (i = 1; i <= n; i++) {
    for (j = 1; j <= m; j++) {
      if (i == 1 && j == 1) continue;
      if ((dp1[i][j] * dp[i][j]) % 1000000007 == dp[n][m]) {
        if (i == n && j == m)
          break;
        else
          cout << 1 << endl;
        return 0;
      }
    }
  }
  cout << 2 << endl;
}
