#include <bits/stdc++.h>
using namespace std;
int gox[] = {1, 0};
int goy[] = {0, 1};
int n, m;
vector<int> ok[1000010], ch[1000010];
vector<pair<int, int> > tr[1000010];
void dfs(int i, int j) {
  ok[i][j] = 1;
  for (int k = 0; k < 2; k++) {
    int x = i + gox[k], y = j + goy[k];
    if (ok[x][y] == 0 && x >= 1 && x <= n && y >= 1 && y <= m &&
        ch[x][y] == 0) {
      dfs(x, y);
      tr[x][y] = {i, j};
    }
  }
}
int main() {
  cin >> n >> m;
  ch[0].resize(m + 10);
  tr[0].resize(m + 10);
  ok[0].resize(m + 10);
  ch[n + 1].resize(m + 10);
  tr[n + 1].resize(m + 10);
  ok[n + 1].resize(m + 10);
  for (int i = 1; i <= n; i++) {
    ch[i].resize(m + 10);
    tr[i].resize(m + 10);
    ok[i].resize(m + 10);
    for (int j = 1; j <= m; j++) {
      char x;
      cin >> x;
      if (x == '#') ch[i][j] = 1;
    }
  }
  dfs(1, 1);
  if (ok[n][m] == 0) {
    cout << 0;
    return 0;
  }
  int curx = n, cury = m;
  while (curx != 1 || cury != 1) {
    if (curx != n || cury != m) ch[curx][cury] = 1;
    pair<int, int> p = tr[curx][cury];
    curx = p.first, cury = p.second;
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      ok[i][j] = 0;
    }
  }
  dfs(1, 1);
  if (ok[n][m] == 0) {
    cout << 1;
    return 0;
  }
  cout << 2;
}
