#include <bits/stdc++.h>
using namespace std;
int n, m;
vector<string> s;
int main() {
  cin >> n >> m;
  vector<vector<int>> path(n);
  vector<vector<int>> pathb(n);
  for (int i = 0; i < n; i++) {
    string tmp;
    cin >> tmp;
    s.push_back(tmp);
  }
  if (m == 1) {
    int ok = 1;
    for (int i = 0; i < n; i++) {
      if (s[i][0] == '#') {
        ok = 0;
        break;
      }
    }
    printf("%d\n", ok);
    return 0;
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (i == 0 && j == 0)
        path[0].push_back(1);
      else if (i == 0) {
        if (s[i][j] == '#')
          path[0].push_back(0);
        else
          path[0].push_back(path[0][j - 1]);
      } else if (j == 0) {
        if (s[i][j] == '#')
          path[i].push_back(0);
        else
          path[i].push_back(path[i - 1][0]);
      } else {
        if (s[i][j] == '#')
          path[i].push_back(0);
        else
          path[i].push_back(path[i - 1][j] | path[i][j - 1]);
      }
    }
  }
  for (int i = n - 1; i >= 0; i--) {
    int tmp = 0;
    for (int j = m - 1; j >= 0; j--) {
      if (i == n - 1 && j == m - 1)
        pathb[i].push_back(1);
      else if (i == n - 1) {
        if (s[i][j] == '#')
          pathb[i].push_back(0);
        else
          pathb[i].push_back(pathb[i][tmp - 1]);
      } else if (j == m - 1) {
        if (s[i][j] == '#')
          pathb[i].push_back(0);
        else
          pathb[i].push_back(pathb[i + 1][m - 1]);
      } else {
        if (s[i][j] == '#')
          pathb[i].push_back(0);
        else
          pathb[i].push_back(pathb[i][tmp - 1] | pathb[i + 1][j]);
      }
      tmp++;
    }
    reverse(pathb[i].begin(), pathb[i].end());
  }
  if (path[n - 1][m - 1] == 0) {
    printf("0\n");
    return 0;
  }
  int x = 0, y = 1;
  bool down = false;
  for (int t = 0; t < n + m - 3; t++) {
    if (y == m) {
      down = true;
      x++;
      y--;
    }
    int a = x, b = y, cnt = 0;
    while (a < n && b >= 0) {
      if (s[a][b] == '.' && path[a][b] && pathb[a][b]) cnt++;
      a++;
      b--;
    }
    if (cnt == 1) {
      printf("1\n");
      return 0;
    }
    if (down) {
      x++;
    } else {
      y++;
    }
  }
  printf("2\n");
  return 0;
}
