#include <bits/stdc++.h>
using namespace std;
template <class T>
using max_pq = priority_queue<T>;
template <class T>
using min_pq = priority_queue<T, vector<T>, greater<T>>;
vector<string> split(const string& s, char c) {
  vector<string> v;
  stringstream second(s);
  string x;
  while (getline(second, x, c)) v.emplace_back(x);
  return move(v);
}
template <typename T, typename... Args>
inline string arrStr(T arr, long long n) {
  stringstream s;
  s << "[";
  for (long long i = 0; i < n - 1; i++) s << arr[i] << ",";
  s << arr[n - 1] << "]";
  return s.str();
}
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  cerr << name << " : " << arg1 << "\n";
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << " : " << arg1 << " | ";
  __f(comma + 1, args...);
}
long long oo = 0x3f3f3f3f;
long long n, m;
vector<vector<bool>> visited;
bool dfs(long long i, long long j) {
  if (visited[i][j] == 0) return 0;
  if (i == n - 1 && j == m - 1) {
    return 1;
  }
  visited[i][j] = 0;
  if (i < n - 1 && dfs(i + 1, j)) return 1;
  if (j < m - 1 && dfs(i, j + 1)) return 1;
  return 0;
}
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  cin >> n >> m;
  visited.resize(n, vector<bool>(m));
  for (long long i = 0; i < n; i++) {
    for (long long j = 0; j < m; j++) {
      char c;
      cin >> c;
      if (c == '.') visited[i][j] = 1;
    }
  }
  long long ans = 0;
  while (dfs(0, 0)) {
    ans++;
    visited[0][0] = 1;
    visited[n - 1][m - 1] = 1;
  }
  cout << ans;
  return 0;
}
