#include <bits/stdc++.h>
using namespace std;
const long long int mod = 1e14 + 7891;
void solve(long long int q) {
  long long int n, m;
  cin >> n >> m;
  char grid[n + 1][m + 1];
  for (long long int i = 1; i <= n; i++) {
    for (long long int j = 1; j <= m; j++) {
      cin >> grid[i][j];
    }
  }
  long long int dp1[n + 5][m + 5];
  long long int dp2[n + 5][m + 5];
  memset(dp1, 0, sizeof(dp1));
  memset(dp2, 0, sizeof(dp2));
  dp1[n][m] = 1;
  for (long long int i = n; i >= 1; i--) {
    for (long long int j = m; j >= 1; j--) {
      if (i == n and j == m) continue;
      if (grid[i][j] == '.') {
        dp1[i][j] = dp1[i + 1][j] + dp1[i][j + 1];
        dp1[i][j] %= mod;
      } else {
        dp1[i][j] = 0;
      }
    }
  }
  dp2[1][1] = 1;
  for (long long int i = 1; i <= n; i++) {
    for (long long int j = 1; j <= m; j++) {
      if (i == 1 and j == 1) continue;
      if (grid[i][j] == '.') {
        dp2[i][j] = dp2[i - 1][j] + dp2[i][j - 1];
        dp2[i][j] %= mod;
      } else {
        dp2[i][j] = 0;
      }
    }
  }
  long long int dp3[n + 5][m + 5];
  memset(dp3, 0, sizeof(dp3));
  vector<long long int> v[n + m + 1];
  for (long long int i = 1; i <= n; i++) {
    for (long long int j = 1; j <= m; j++) {
      if (dp1[i][j] > 0 and dp2[i][j] > 0) {
        dp3[i][j] = 1;
      }
    }
  }
  for (long long int i = 1; i <= n; i++) {
    for (long long int j = 1; j <= m; j++) {
      if (dp3[i][j] > 0) {
        v[i + j].push_back(1);
      }
    }
  }
  if (dp3[n][m] == 0) {
    cout << 0;
    return;
  }
  for (long long int i = 3; i < n + m; i++) {
    long long int cmp = v[i].size();
    if (cmp == 1) {
      cout << 1;
      return;
    }
    if (cmp == 0) {
      cout << 0;
      return;
    }
  }
  cout << 2;
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int q;
  q = 1;
  for (long long int i = 1; i <= q; i++) {
    solve(i);
  }
  return 0;
}
