#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
long long ncr(long long n, long long r) {
  long long res = 1;
  if (r > n - r) r = n - r;
  for (long long i = 0; i < r; i++) {
    res *= n - i;
    res /= i + 1;
  }
  return res;
}
clock_t time_p = clock();
void rtime() {
  time_p = clock() - time_p;
  cerr << "Time Taken : " << (float)(time_p) / CLOCKS_PER_SEC << "\n";
}
long long power(long long a, long long b, long long m = mod) {
  long long ans = 1;
  a = a % m;
  while (b > 0) {
    if (b & 1) ans = (1ll * a * ans) % m;
    b >>= 1;
    a = (1ll * a * a) % m;
  }
  return ans;
}
long long rr[] = {0, 1, 1, 1, 0, -1, -1, -1};
long long cc[] = {1, 1, 0, -1, -1, -1, 0, 1};
long long n, m;
vector<string> s;
long long dfs(long long x, long long y) {
  if (x >= n || y >= m || s[x][y] == '#') return 0;
  if (x == n - 1 && y == m - 1) return 1;
  if (x + y != 0) s[x][y] = '#';
  return dfs(x + 1, y) || dfs(x, y + 1);
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  long long t = 1;
  while (t--) {
    cin >> n >> m;
    string a;
    for (long long i = 0; i < n; i++) {
      cin >> a;
      s.push_back(a);
    }
    if (!dfs(0, 0)) return cout << 0, 0;
    if (dfs(0, 0)) return cout << 2, 0;
    cout << 1, 0;
  }
  rtime();
  return 0;
}
