#include <bits/stdc++.h>
char map[2000001], visited[2000001];
int main() {
  int n, m, i, j, k, len;
  scanf("%d %d ", &n, &m);
  for (i = 0; i < n; ++i) scanf("%[.#\n]", map);
  *visited = -1;
  for (i = 0; i < n + m - 2; ++i) {
    for (j = (i + 1 < m - 1 ? i + 1 : m - 1),
        k = (0 > i - m + 2 ? 0 : i - m + 2);
         j > -1 && k < n; --j, ++k) {
      if (map[j + (m + 1) * k] == '#') continue;
      if (j > 0)
        if (visited[j - 1 + (m + 1) * k]) visited[j + (m + 1) * k] = -1;
      if (k > 0)
        if (visited[j + (m + 1) * (k - 1)]) visited[j + (m + 1) * k] = -1;
    }
  }
  if (visited[m - 1 + (m + 1) * (n - 1)] == 0) {
    puts("0");
    return 0;
  }
  visited[m - 1 + (m + 1) * (n - 1)] = 1;
  for (i = n + m - 4; i > -2; --i) {
    len = 0;
    for (j = (i + 1 < m - 1 ? i + 1 : m - 1),
        k = (0 > i - m + 2 ? 0 : i - m + 2);
         j > -1 && k < n; --j, ++k) {
      if (visited[j + (m + 1) * k] != -1) continue;
      if (j < m - 1)
        if (visited[j + 1 + (m + 1) * k] == 1) visited[j + (m + 1) * k] = 1;
      if (k < n - 1)
        if (visited[j + (m + 1) * (k + 1)] == 1) visited[j + (m + 1) * k] = 1;
      if (visited[j + (m + 1) * k] == 1) ++len;
    }
    if (len == 1 && i != -1) {
      puts("1");
      return 0;
    }
  }
  puts("2");
  return 0;
}
