#include <bits/stdc++.h>
using namespace std;
long long MOD = 1000000007;
signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  long long N, M;
  cin >> N >> M;
  vector<string> S(N);
  for (long long i = 0; i < N; i++) {
    cin >> S[i];
  }
  vector<vector<long long> > A(N, vector<long long>(M, 0));
  A[N - 1][M - 1] = 1;
  for (long long i = N - 1; i >= 0; i--) {
    for (long long j = M - 1; j >= 0; j--) {
      if (S[i][j] == '#') continue;
      if (i < N - 1) {
        if (A[i + 1][j] == 1) A[i][j] = 1;
      }
      if (j < M - 1) {
        if (A[i][j + 1] == 1) A[i][j] = 1;
      }
    }
  }
  if (A[0][0] == 0) {
    cout << 0 << endl;
    return 0;
  }
  long long X = 0;
  long long Y = 0;
  long long res = 1;
  while (true) {
    if (X < N - 1 && A[X + 1][Y] == 1) {
      X++;
    } else if (Y < M - 1 && A[X][Y + 1] == 1) {
      Y++;
    } else {
      cerr << "ha?" << endl;
    }
    if (X == N - 1 && Y == M - 1) {
      break;
    } else {
      A[X][Y] = 0;
    }
  }
  X = 0;
  Y = 0;
  while (true) {
    if (Y < M - 1 && A[X][Y + 1] == 1) {
      Y++;
    } else if (X < N - 1 && A[X + 1][Y] == 1) {
      X++;
    } else {
      break;
    }
    if (X == N - 1 && Y == M - 1) {
      res = 2;
      break;
    }
  }
  cout << res << endl;
}
