#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9;
const int maxn = 2005000;
int b, g, n, m;
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};
int ok[maxn], vis[maxn], vis2[maxn], mp[maxn];
char get() {
  char ch;
  ch = getchar();
  while (ch != '#' && ch != '.') ch = getchar();
  return ch;
}
int p(int x, int y) { return (x - 1) * m + y; }
void dfs(int x, int y) {
  vis[p(x, y)] = 1;
  for (int i = 0; i <= 1; i++) {
    int xx = x + dx[i], yy = y + dy[i];
    if (1 <= xx && xx <= n && 1 <= yy && yy <= m && !vis[p(xx, yy)] &&
        mp[p(xx, yy)] == '.')
      dfs(xx, yy);
  }
}
void dfs2(int x, int y) {
  vis2[p(x, y)] = 1;
  for (int i = 2; i <= 3; i++) {
    int xx = x + dx[i], yy = y + dy[i];
    if (1 <= xx && xx <= n && 1 <= yy && yy <= m && !vis2[p(xx, yy)] &&
        mp[p(xx, yy)] == '.')
      dfs2(xx, yy);
  }
}
int main() {
  scanf("%d%d", &n, &m);
  for (int x = 1; x <= n; x++)
    for (int y = 1; y <= m; y++) {
      mp[p(x, y)] = get();
    }
  dfs(1, 1);
  dfs2(n, m);
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++)
      if (vis[p(i, j)] && vis2[p(i, j)]) {
        ok[i + j]++;
      }
  if (!vis[p(n, m)]) {
    puts("0");
    return 0;
  }
  int ans = 2;
  for (int i = 3; i <= n + m - 1; i++) ans = min(ans, ok[i]);
  printf("%d\n", ans);
  return 0;
}
