#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 1;
char s[maxn];
int n, m, vis[maxn], ans, dir[2][2] = {1, 0, 0, 1};
void dfs(int x) {
  if (ans) return;
  if (x == (n * m - 1)) {
    ans++;
    return;
  }
  int X = x / m, Y = x % m;
  for (int i = 0; i < 2; ++i) {
    int tx = X + dir[i][0], ty = Y + dir[i][1];
    if (tx >= n || ty >= m || vis[tx * m + ty]) continue;
    vis[tx * m + ty] = 1;
    dfs(tx * m + ty);
    if (ans) return;
  }
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; ++i) {
    scanf("%s", s + i * m);
    for (int j = i * m; j < (i + 1) * m; ++j)
      if (s[j] == '#') vis[j] = 1;
  }
  vis[0] = 1, ans = vis[n * m - 1] = 0;
  dfs(0);
  if (!ans) {
    puts("0");
    return 0;
  }
  vis[0] = 1, ans = vis[n * m - 1] = 0;
  dfs(0);
  printf("%d\n", ans ? 2 : 1);
}
