#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:134217728")
using namespace std;
template <class T>
T abs(T x) {
  return x > 0 ? x : -x;
}
int m;
int n;
string s[1020];
queue<pair<pair<int, int>, int> > q, nq;
int ans[1001][1001][4];
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
int good(int x, int y) { return x >= 0 && x < n && y >= 0 && y < m; }
void parse(pair<pair<int, int>, int> o) {
  int x = o.first.first;
  int y = o.first.second;
  int p = o.second;
  int nx = x + dx[p];
  int ny = y + dy[p];
  if (good(nx, ny)) {
    if (ans[nx][ny][p] == -1 || ans[nx][ny][p] > ans[x][y][p]) {
      ans[nx][ny][p] = ans[x][y][p];
      q.push(make_pair(make_pair(nx, ny), p));
    }
  }
  int sp = p;
  if (s[x][y] == '#') {
    for (int p = 0; p < (4); p++) {
      int nx = x + dx[p];
      int ny = y + dy[p];
      if (good(nx, ny)) {
        if (ans[nx][ny][p] == -1) {
          ans[nx][ny][p] = ans[x][y][sp] + 1;
          nq.push(make_pair(make_pair(nx, ny), p));
        }
      }
    }
  }
}
int main() {
  cin >> n >> m;
  m++;
  for (int i = 0; i < (n); i++) {
    cin >> s[i];
    s[i] += ".";
  }
  memset(ans, -1, sizeof(ans));
  q.push(make_pair(make_pair(0, 0), 1));
  ans[0][0][1] = 0;
  while (1) {
    while (!q.empty()) {
      parse(q.front());
      q.pop();
    }
    swap(q, nq);
    if (q.empty()) break;
  }
  cout << ans[n - 1][m - 1][1] << endl;
  return 0;
}
