#include <bits/stdc++.h>
using namespace std;
map<int, int> vis;
string s[1000009];
int n, m, i;
bool dfs(int x, int y) {
  if (x == n - 1 && y == m - 1) return true;
  if (x < 0 || y < 0 || x >= n || y >= m || vis[y + x * m] == 1 ||
      s[x][y] == '#')
    return false;
  if (x || y) {
    vis[y + x * m] = 1;
  }
  return dfs(x + 1, y) || dfs(x, y + 1);
}
int main() {
  cin >> n >> m;
  for (i = 0; i < n; i++) cin >> s[i];
  if (dfs(0, 0) == false) {
    cout << "0";
    return 0;
  }
  if (dfs(0, 0) == false) {
    cout << "1";
    return 0;
  }
  cout << "2";
}
