#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
const long long INF = mod * mod;
const long double eps = 1e-5;
const long double pi = acos(-1.0);
int h, w;
void solve() {
  cin >> h >> w;
  vector<string> mp(h);
  for (int i = 0; i < h; i++) {
    cin >> mp[i];
  }
  vector<vector<bool>> cans(h);
  vector<vector<bool>> cang(h);
  for (int i = 0; i < h; i++) {
    cans[i].resize(w, false);
    cang[i].resize(w, false);
  }
  cans[0][0] = true;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (!cans[i][j]) continue;
      if (j + 1 < w && mp[i][j + 1] == '.') {
        cans[i][j + 1] = true;
      }
      if (i + 1 < h && mp[i + 1][j] == '.') {
        cans[i + 1][j] = true;
      }
    }
  }
  if (!cans[h - 1][w - 1]) {
    cout << 0 << endl;
    return;
  }
  cang[h - 1][w - 1] = true;
  for (int i = h - 1; i >= 0; i--) {
    for (int j = w - 1; j >= 0; j--) {
      if (!cang[i][j]) continue;
      if (i - 1 >= 0 && mp[i - 1][j] == '.') {
        cang[i - 1][j] = true;
      }
      if (j - 1 >= 0 && mp[i][j - 1] == '.') {
        cang[i][j - 1] = true;
      }
    }
  }
  for (int i = 1; i <= h + w - 3; i++) {
    int x = i, y = 0;
    if (x > h - 1) {
      int dif = x - (h - 1);
      x -= dif;
      y += dif;
    }
    int cnt = 0;
    while (x >= 0 && y < w) {
      if (cans[x][y] && cang[x][y]) cnt++;
      x--;
      y++;
    }
    if (cnt == 1) {
      cout << 1 << endl;
      return;
    }
  }
  cout << 2 << endl;
}
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  solve();
  return 0;
}
