#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
vector<string> path;
vector<bool> vis(1000005, false);
int n, m;
bool dfs(int i, int j) {
  if (i < 0 or i >= n or j < 0 or j >= m or vis[i * m + j] or path[i][j] == '#')
    return 0;
  if (i == n - 1 and j == m - 1) return 1;
  if (i + j > 0) vis[i * m + j] = true;
  return dfs(i + 1, j) or dfs(i, j + 1);
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> n >> m;
  for (__typeof(n) i = (0) - (0 > n); i != (n) - (0 > n);
       i += 1 - 2 * (0 > n)) {
    string s;
    cin >> s;
    path.push_back(s);
  }
  if (not dfs(0, 0))
    cout << 0 << '\n';
  else if (not dfs(0, 0))
    cout << 1 << '\n';
  else
    cout << 2 << '\n';
  return 0;
}
