#include <bits/stdc++.h>
using namespace std;
int read() {
  int res = 0, f = 1;
  char c = getchar();
  while (!isdigit(c) && c != '-') c = getchar();
  if (c == '-') f = -1, c = getchar();
  while (isdigit(c)) res = (res << 3) + (res << 1) + (c ^ 48), c = getchar();
  return res * f;
}
const int maxn = 2e6 + 10;
int n, m, a[maxn], dp[maxn], f[maxn];
int c(int i, int j) {
  if (i < 1 || j < 1 || i > n || j > m) return 0;
  return (i - 1) * m + j;
}
int main() {
  n = read();
  m = read();
  for (int i = 1; i <= n; i++, getchar())
    for (int j = 1; j <= m; j++) a[c(i, j)] = getchar() == '.';
  dp[1] = 1;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++)
      if (a[c(i, j)]) dp[c(i, j)] |= dp[c(i - 1, j)] || dp[c(i, j - 1)];
  f[c(n, m)] = 1;
  for (int i = n; i; i--)
    for (int j = m; j; j--)
      if (a[c(i, j)]) f[c(i, j)] |= f[c(i + 1, j)] || f[c(i, j + 1)];
  if (!dp[c(n, m)]) {
    printf("0\n");
    return 0;
  }
  int ans = 2;
  for (int k = 3; k <= n + m - 1; k++) {
    int tmp = 0;
    for (int i = max(1, k - m); i <= min(n, k - 1); i++) {
      tmp += dp[c(i, k - i)] && f[c(i, k - i)];
    }
    ans = min(ans, tmp);
  }
  printf("%d\n", ans);
  return 0;
}
