#include <bits/stdc++.h>
using ll = long long;
using namespace std;
int dir[] = {0, 1, 0, -1};
int n, m;
int kabegiwa(bool *map, int d, int loc, int id) {
  map[loc] = false;
  map[0] = map[n * m - 1] = true;
  if (id == 0 && loc == n * m - 1 || id == 1 && loc == 0) return 1;
  int front = loc + dir[d];
  if (front >= 0 && front < n * m &&
      !(d == 1 && loc % m == m - 1 || d == 3 && loc % m == 0) && map[front] &&
      kabegiwa(map, d, front, id))
    return 1;
  int left = loc + dir[(d + 1) % 4];
  if (left >= 0 && left < n * m &&
      !((d + 1) % 4 == 1 && loc % m == m - 1 ||
        (d + 1) % 4 == 3 && loc % m == 0) &&
      map[left] && kabegiwa(map, d, left, id))
    return 1;
  return 0;
}
int main() {
  cin >> n >> m;
  dir[0] = m;
  dir[2] = -m;
  bool map[n * m];
  string s;
  for (int i = 0; i < n; i++) {
    cin >> s;
    for (int j = 0; j < m; j++) map[i * m + j] = (s[j] == '.');
  }
  int k1 = kabegiwa(map, 0, 0, 0), k2 = kabegiwa(map, 2, n * m - 1, 1);
  cout << k1 + k2 << '\n';
  return 0;
}
