#include <bits/stdc++.h>
using namespace std;
const long long MAX_V = 2e6 + 50;
const long long INF = 0x3f3f3f3f;
struct edge {
  long long to, cap, rev;
  edge(long long _to, long long _cap, long long _rev)
      : to(_to), cap(_cap), rev(_rev) {}
};
vector<edge> G[MAX_V];
vector<vector<long long> > ggg(MAX_V);
long long level[MAX_V];
long long iter[MAX_V];
long long n, m;
char ssss[MAX_V];
long long dx[] = {0, 1}, dy[] = {1, 0};
void add_edge(long long from, long long to, long long cap) {
  G[from].push_back(edge(to, cap, G[to].size()));
  G[to].push_back(edge(from, 0, G[from].size() - 1));
}
void bfs(long long s) {
  memset(level, -1, sizeof(level));
  queue<long long> que;
  level[s] = 0;
  que.push(s);
  while (!que.empty()) {
    long long v = que.front();
    que.pop();
    for (long long i = 0; i < G[v].size(); i++) {
      edge &e = G[v][i];
      if (e.cap > 0 && level[e.to] < 0) {
        level[e.to] = level[v] + 1;
        que.push(e.to);
      }
    }
  }
}
long long dfs(long long v, long long t, long long f) {
  if (v == t) {
    return f;
  }
  for (long long &i = iter[v]; i < G[v].size(); i++) {
    edge &e = G[v][i];
    if (e.cap > 0 && level[v] < level[e.to]) {
      long long d = dfs(e.to, t, min(f, e.cap));
      if (d > 0) {
        e.cap -= d;
        G[e.to][e.rev].cap += d;
        return d;
      }
    }
  }
  return 0;
}
long long max_flow(long long s, long long t) {
  long long flow = 0;
  for (;;) {
    bfs(s);
    if (level[t] < 0) {
      return flow;
    }
    memset(iter, 0, sizeof(iter));
    long long f;
    while ((f = dfs(s, t, INF)) > 0) {
      flow += f;
    }
  }
  return flow;
}
int32_t main() {
  scanf("%d%d", &n, &m);
  for (long long i = 0; i < n; i++) {
    scanf("%s", ssss);
    for (long long j = 0; j < m; j++) {
      if (ssss[j] == '#')
        ggg[i].push_back(0);
      else
        ggg[i].push_back(1);
    }
  }
  for (long long i = 0; i < n; i++) {
    for (long long j = 0; j < m; j++) {
      if (ggg[i][j] == 0)
        continue;
      else {
        if (i == 0 && j == 0) {
          for (long long k = 0; k < 2; k++) {
            long long nx = i + dx[k], ny = j + dy[k];
            if (nx >= 0 && ny >= 0 && nx < n && ny < m && ggg[nx][ny] == 1) {
              add_edge(i * m + j, nx * m + ny, 1);
            }
          }
        } else if (i == n - 1 && j == m - 1) {
          continue;
        } else {
          add_edge(i * m + j, i * m + j + n * m, 1);
          for (long long k = 0; k < 2; k++) {
            long long nx = i + dx[k], ny = j + dy[k];
            if (nx >= 0 && ny >= 0 && nx < n && ny < m && ggg[nx][ny] == 1) {
              add_edge(i * m + j + n * m, nx * m + ny, 1);
            }
          }
        }
      }
    }
  }
  long long s = 0ll, t = (n - 1ll) * m + m - 1;
  printf("%d\n", max_flow(s, t));
  return 0;
}
