#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
;
const int N = 1e7 + 10;
const double pi = acos(-1);
const int inf = 0x3f3f3f3f;
const int M = 50000 + 5;
string s[N];
int vis[N];
int p, n, m;
bool dfs(int x, int y) {
  if (x < 0 || y < 0 || x >= n || y >= m || vis[x * m + y] || s[x][y] == '#')
    return false;
  if (x == n - 1 && y == m - 1) return true;
  vis[x * m + y] = 1;
  return dfs(x + 1, y) || dfs(x, y + 1);
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; i++) cin >> s[i];
  memset(vis, 0, sizeof(vis));
  bool f = dfs(0, 0);
  if (!f)
    printf("0\n");
  else {
    vis[0] = 0;
    vis[(n - 1) * m + m - 1] = 0;
    f = dfs(0, 0);
    if (f)
      printf("2\n");
    else
      printf("1\n");
  }
  return 0;
}
