#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1000 + 10;
int mn[MAXN][MAXN];
queue<int> q;
bool satr[MAXN], sotun[MAXN];
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < n; i++)
    for (int j = 0; j <= m; j++) mn[i][j] = -1;
  string s[n];
  for (int i = 0; i < n; i++) {
    cin >> s[i];
  }
  int x, y, k;
  bool flag = false;
  for (int i = 0; i <= m; i++) {
    if (s[0][i] == '#' and flag == false)
      q.push(0), q.push(i), flag = true, mn[0][i] = 0;
  }
  while (q.size()) {
    x = q.front();
    q.pop();
    y = q.front();
    q.pop();
    if (satr[x] == false) {
      satr[x] = true;
      for (int i = 0; i <= m; i++) {
        if (mn[x][i] == -1 and s[x][i] == '#' && i != y) q.push(x), q.push(i);
        if (mn[x][i] == -1) mn[x][i] = mn[x][y] + 1;
        if (x == 0) mn[x][i] = 0;
      }
    }
    if (sotun[y] == false) {
      sotun[y] = true;
      for (int i = 0; i < n; i++) {
        if (mn[i][y] == -1 and s[i][y] == '#' && i != x) q.push(i), q.push(y);
        if (mn[i][y] == -1) mn[i][y] = mn[x][y] + 1;
      }
    }
  }
  cout << mn[n - 1][m];
  return 0;
}
