#include <bits/stdc++.h>
using namespace std;
char s[10000005];
bool vis[10000005];
int n, m;
int gt(int x, int y) { return (x - 1) * m + y; }
bool dfs(int x, int y) {
  bool flag = false;
  if (x == n && y == m) {
    return true;
  }
  vis[gt(x, y)] = true;
  if (x + 1 <= n && s[gt(x + 1, y)] == '.' && !vis[gt(x + 1, y)]) {
    vis[gt(x + 1, y)] = true;
    flag = flag | dfs(x + 1, y);
  }
  if (y + 1 <= m && s[gt(x, y + 1)] == '.' && !vis[gt(x, y + 1)]) {
    if (flag) return true;
    vis[gt(x, y + 1)] = true;
    flag = flag | dfs(x, y + 1);
  };
  return flag;
}
int main() {
  int i, j;
  memset(vis, false, sizeof(vis));
  scanf("%d%d", &n, &m);
  for (i = 1; i <= n; ++i) scanf("%s", s + ((i - 1) * m + 1));
  if (!dfs(1, 1)) {
    printf("0");
    return 0;
  } else {
    vis[gt(n, m)] = false;
    if (dfs(1, 1))
      printf("2");
    else
      printf("1");
  }
  printf("\n");
}
