#include <bits/stdc++.h>
using namespace std;
int n, m;
vector<vector<int>> adj;
vector<vector<int>> vis;
int dfs1(int a, int b) {
  if (a == n - 1 and b == m - 1) return 1;
  vis[a][b] = 1;
  if (a + 1 < n and adj[a + 1][b] and !vis[a + 1][b])
    if (dfs1(a + 1, b)) return 1;
  if (b + 1 < m and adj[a][b + 1] and !vis[a][b + 1])
    if (dfs1(a, b + 1)) return 1;
  vis[a][b] = 2;
  return 0;
}
int dfs2(int a, int b) {
  if (a == n - 1 and b == m - 1) return 1;
  vis[a][b] = 1;
  if (a + 1 < n and adj[a + 1][b] and vis[a + 1][b] != 1)
    if (dfs2(a + 1, b)) return 1;
  if (b + 1 < m and adj[a][b + 1] and vis[a][b + 1] != 1)
    if (dfs2(a, b + 1)) return 1;
  return 0;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> m;
  adj = vector<vector<int>>(n, vector<int>(m));
  for (int i = 0; i < n; ++i) {
    string s;
    cin >> s;
    for (int j = 0; j < m; ++j) {
      if (s[j] == '.')
        adj[i][j] = 1;
      else
        adj[i][j] = 0;
    }
  }
  int a = 0;
  vis = vector<vector<int>>(n, vector<int>(m, 0));
  a += dfs1(0, 0);
  a += dfs2(0, 0);
  cout << a << '\n';
}
