#include <bits/stdc++.h>
using namespace std;
int n, m;
vector<bool> v[1000005];
vector<bool> b[1000005];
bool f = 0;
void dfs(int i, int j) {
  if (i < 1 || j < 1 || i > n || j > m || v[i][j]) return;
  if (i == n && j == m) f = 1;
  if (f) return;
  v[i][j] = 1;
  dfs(i + 1, j);
  dfs(i, j + 1);
}
int main() {
  cin >> n >> m;
  int i, j;
  for (i = 1; i <= n; i++) {
    v[i].resize(m + 2);
    b[i].resize(m + 2);
    for (j = 1; j <= m; j++) {
      char a;
      cin >> a;
      if (a == '#') v[i][j] = 1;
    }
  }
  dfs(1, 1);
  if (!f)
    cout << "0";
  else {
    v[1][1] = f = 0;
    dfs(1, 1);
    if (f == 1)
      cout << "2";
    else
      cout << "1";
  }
  return 0;
}
