#include <bits/stdc++.h>
using namespace std;
long long int n, m;
bool dfs1(long long int row, long long int col, vector<string>& data) {
  vector<vector<bool>> path(n, vector<bool>(m, 0));
  for (long long int i = col; i < m; i++) {
    if (data[0][i] == '#') break;
    path[0][i] = 1;
  }
  for (long long int i = row; i < n; i++) {
    if (data[i][0] == '#') break;
    path[i][0] = 1;
  }
  vector<vector<bool>> p2(n, vector<bool>(m, 0));
  for (long long int i = 1; i < n; i++) {
    for (long long int j = 1; j < m; j++) {
      if (data[i][j] == '.')
        path[i][j] = max(path[i - 1][j], path[i][j - 1]);
      else
        path[i][j] = 0;
    }
  }
  if (path[n - 1][m - 1] == false) return false;
  long long int i = n - 1;
  long long int j = m - 1;
  while (i > 0 or j > 0) {
    if (i > 0 and path[i - 1][j] == 1) {
      p2[i - 1][j] = 1;
      i--;
    } else {
      p2[i][j - 1] = 1;
      j--;
    }
  }
  for (long long int i = 0; i < n; i++) {
    for (long long int j = 0; j < m; j++) {
      if (p2[i][j] == 1) data[i][j] = '#';
    }
  }
  data[0][0] = '.';
  return true;
}
int main() {
  cin >> n >> m;
  vector<string> data(n);
  for (long long int i = 0; i < n; i++) cin >> data[i];
  bool x = false;
  if (m > 1 and data[0][1] != '#') {
    x = dfs1(0, 1, data);
  }
  if (!x) {
    if (n > 1 and data[1][0] != '#') {
      x = dfs1(1, 0, data);
    } else {
      cout << 0;
      return 0;
    }
    if (x) {
      cout << 1;
      return 0;
    } else {
      cout << 0;
      return 0;
    }
  } else {
    if (n > 1 and data[1][0] != '#') {
      x = dfs1(1, 0, data);
    } else {
      cout << 1;
      return 0;
    }
    if (x) {
      cout << 2;
      return 0;
    } else {
      cout << 1;
      return 0;
    }
  }
  return 0;
}
