#include <bits/stdc++.h>
using namespace std;
const int MaxN = 1005;
char mp[MaxN][MaxN];
int N, M;
int MinN[MaxN], MinM[MaxN];
int qn[3 * MaxN], qf[3 * MaxN];
int main() {
  scanf("%d%d", &N, &M);
  for (int i = 0; i < N; ++i) {
    scanf("%s", mp + i);
  }
  memset(MinN, -1, sizeof(MinN));
  memset(MinM, -1, sizeof(MinM));
  MinN[N - 1] = 0;
  int head = 0, tail = 0;
  qn[tail] = N - 1, qf[tail++] = 0;
  while (head < tail) {
    int nn = qn[head], nf = qf[head];
    head++;
    if (nf == 0) {
      for (int i = 0; i < M; ++i) {
        if (mp[nn][i] == '#') {
          if (MinM[i] == -1) {
            MinM[i] = MinN[nn] + 1;
            qn[tail] = i, qf[tail++] = 1;
          }
        }
      }
    } else {
      for (int i = 0; i < N; ++i) {
        if (mp[i][nn] == '#') {
          if (MinN[i] == -1) {
            MinN[i] = MinM[nn] + 1;
            qn[tail] = i, qf[tail++] = 0;
          }
        }
      }
    }
  }
  printf("%d\n", MinN[0]);
}
