#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 5;
char c[maxn];
bool vis[maxn];
int n, m;
bool dfs(int x, int y) {
  if (x == n && y == m) return 1;
  if (x < 1 || x > n || y < 1 || y > m) return 0;
  if (c[(x - 1) * m + y] == '#' || vis[(x - 1) * m + y]) return 0;
  vis[(x - 1) * m + y] = 1;
  if (dfs(x + 1, y)) return 1;
  return dfs(x, y + 1);
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> m;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) cin >> c[(i - 1) * m + j];
  if (!dfs(1, 1)) return cout << 0 << '\n', 0;
  vis[1] = 0;
  if (dfs(1, 1)) return cout << 2 << '\n', 0;
  cout << 1 << '\n';
  return 0;
}
