#include <bits/stdc++.h>
using namespace std;
const long long MAXN = 1e6 + 10;
inline void rd(long long &s) {
  s = 0;
  long long t = 1, k = getchar();
  for (; k < '0' || k > '9'; k = getchar())
    if (k == '-') t = -1;
  for (; k >= '0' && k <= '9'; k = getchar())
    s = (s << 1) + (s << 3) + (k ^ 48);
  s *= t;
}
long long n, m;
vector<vector<char> > g;
long long dx[4] = {0, 1};
long long dy[4] = {1, 0};
long long ans = 0;
char c[MAXN];
void dfs(long long x, long long y) {
  if (ans) return;
  if (x == n - 1 && y == m - 1) {
    ans = 1;
    return;
  }
  for (long long i = 0; i < 2; i++) {
    long long nx = x + dx[i], ny = y + dy[i];
    if (nx >= n || ny >= m || g[nx][ny] == '#') continue;
    g[nx][ny] = '#';
    dfs(nx, ny);
    if (ans) return;
  }
}
signed main() {
  rd(n);
  rd(m);
  g.resize(n);
  for (long long i = 0; i < n; i++) {
    g[i].resize(m);
    scanf("%s", c);
    for (long long j = 0; j < m; j++) g[i][j] = c[j];
  }
  ans = 0;
  dfs(0, 0);
  if (ans == 0)
    printf("0\n");
  else {
    ans = 0;
    g[n - 1][m - 1] = '.';
    dfs(0, 0);
    if (ans)
      printf("2\n");
    else
      printf("1\n");
  }
  return 0;
}
