#include <bits/stdc++.h>
using namespace std;
const int N = 1000005;
string _f[N];
int n, m;
bool dfs(int i, int j) {
  if (i == n - 1 && j == m - 1) return true;
  if (i < 0 || i >= n || j < 0 || j >= m || _f[i][j] == '#') return false;
  if (i || j) _f[i][j] = '#';
  return dfs(i + 1, j) || dfs(i, j + 1);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> m;
  for (int i = 0; i < n; ++i) {
    cin >> _f[i];
  }
  if (false == dfs(0, 0)) {
    cout << "0" << endl;
    return 0;
  }
  if (false == dfs(0, 0))
    cout << "1" << endl;
  else
    cout << "2" << endl;
  return 0;
}
