#include <bits/stdc++.h>
using namespace std;
int n, m;
string str[1000005];
int dfs(int i, int j) {
  if (str[i][j] == '#' || i >= n || j >= m) return 0;
  if (i == n - 1 && j == m - 1) return 1;
  str[i][j] = '#';
  return (dfs(i + 1, j) || dfs(i, j + 1));
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < n; i++) cin >> str[i];
  int ans = dfs(0, 0);
  str[0][0] = '.';
  ans += dfs(0, 0);
  cout << ans;
}
