#include <bits/stdc++.h>
using namespace std;
int n, m;
vector<string> s;
int dx[2] = {0, 1};
int dy[2] = {1, 0};
bool is;
int dfs(int x, int y) {
  if (x == n - 1 && y == m - 1) is = 1;
  if (is) return 1;
  s[x][y] = '#';
  int ans = 0;
  for (int i = 0; i < 2; i++) {
    if (is) return 1;
    int cx = x + dx[i], cy = y + dy[i];
    if (cx >= 0 && cx < n && cy >= 0 && cy < m && s[cx][cy] == '.') {
      ans |= dfs(cx, cy);
    }
  }
  return ans;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    string x;
    cin >> x;
    s.push_back(x);
  }
  if (dfs(0, 0) == 0) {
    cout << 0;
    return 0;
  }
  is = 0;
  if (dfs(0, 0) == 0) {
    cout << 1;
    return 0;
  }
  cout << 2;
  return 0;
}
