#include <bits/stdc++.h>
using namespace std;
using ll = long long;
vector<vector<char>> gr;
vector<vector<ll>> dp;
vector<vector<bool>> used;
int n, m;
int s = 0;
int cnt = 0;
bool cons(int x, int y) {
  if (x >= 0 && y >= 0 && x < n && y < m) {
    return true;
  }
  return false;
}
bool c = false;
void dfs(int x, int y) {
  if (c) {
    return;
  }
  int xr, yr;
  int xl, yl;
  if (cnt) {
    xr = x + 1;
    yr = y;
    xl = x;
    yl = y + 1;
  } else {
    xr = x;
    yr = y + 1;
    xl = x + 1;
    yl = y;
  }
  if (cons(xr, yr) && !used[xr][yr] && gr[xr][yr] == '.') {
    if (!c) used[xr][yr] = true;
    if (xr == n - 1 && yr == m - 1) {
      c = true;
      s++;
      return;
    }
    dfs(xr, yr);
  }
  if (cons(xl, yl) && !used[xl][yl] && gr[xl][yl] == '.') {
    if (!c) used[xl][yl] = true;
    if (xl == n - 1 && yl == m - 1) {
      c = true;
      s++;
      return;
    }
    dfs(xl, yl);
  }
  return;
}
int main() {
  cin >> n >> m;
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(nullptr);
  gr.assign(n, vector<char>(m, 0));
  dp.assign(n, vector<ll>(m, 0ll));
  used.assign(n, vector<bool>(m, false));
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> gr[i][j];
    }
  }
  dfs(0, 0);
  c = false;
  used[n - 1][m - 1] = false;
  cnt = 1;
  dfs(0, 0);
  cout << s << '\n';
  return 0;
}
