#include <bits/stdc++.h>
using namespace std;
vector<string> adj;
vector<vector<bool> > vis;
bool dfs(int n, int m, int x, int y) {
  if (x == n - 1 && y == m - 1) {
    return true;
  }
  if (x != 0 || y != 0) {
    vis[x][y] = true;
  }
  bool ret1 = false, ret2 = false;
  if (x + 1 < n && adj[x + 1][y] == '.' && !vis[x + 1][y]) {
    ret1 = dfs(n, m, x + 1, y);
  }
  if (ret1) return ret1;
  if (y + 1 < m && adj[x][y + 1] == '.' && !vis[x][y + 1]) {
    ret2 = dfs(n, m, x, y + 1);
  }
  return ret2;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n, m;
  cin >> n >> m;
  vis.resize(n);
  for (int i = 0; i < n; i++) {
    vis[i].assign(m, false);
    string s;
    cin >> s;
    adj.push_back(s);
  }
  int ans = 0;
  for (int i = 0; i < 2; i++) {
    ans += dfs(n, m, 0, 0);
  }
  cout << ans << '\n';
  return 0;
}
