#include <bits/stdc++.h>
using namespace std;
int main() {
  int r, c;
  cin >> r;
  cin >> c;
  vector<vector<bool> > a(r);
  for (int i = 0; i < r; i++) a[i].resize(c);
  char t_c;
  for (int i = 0; i < r; i++) {
    for (int j = 0; j < c; j++) {
      cin >> t_c;
      if (t_c == '.')
        a[i][j] = true;
      else
        a[i][j] = false;
    }
  }
  vector<vector<bool> > b(r);
  vector<vector<bool> > d(r);
  b = a;
  d = a;
  b[0][0] = true;
  d[r - 1][c - 1] = true;
  for (int i = 1; i <= r + c - 2; i++) {
    for (int j = max(0, i - c + 1); j <= min(r - 1, i); j++) {
      b[j][i - j] = false;
      if (a[j][i - j] == true) {
        if (j != 0)
          if (b[j - 1][i - j] == true) b[j][i - j] = true;
        if (i - j != 0)
          if (b[j][i - j - 1] == true) b[j][i - j] = true;
      }
    }
  }
  for (int i = r + c - 3; i >= 0; i--) {
    for (int j = max(0, i - c + 1); j <= min(r - 1, i); j++) {
      d[j][i - j] = false;
      if (a[j][i - j] == true) {
        if (j != r - 1)
          if (d[j + 1][i - j] == true) d[j][i - j] = true;
        if (i - j != c - 1)
          if (d[j][i - j + 1] == true) d[j][i - j] = true;
      }
    }
  }
  bool weak = false;
  for (int i = 1; i <= r + c - 3; i++) {
    int cnt1 = 0;
    for (int j = max(0, i - c + 1); j <= min(r - 1, i); j++) {
      if (b[j][i - j] && d[j][i - j]) cnt1++;
    }
    if (cnt1 < 2) weak = true;
  }
  if (!d[0][0])
    cout << "0";
  else if (weak)
    cout << "1";
  else
    cout << "2";
  return 0;
}
