#include <bits/stdc++.h>
using namespace std;
const int MaxN = 1e3 + 10;
long dis[MaxN][MaxN];
long mark[MaxN][MaxN];
long n, m;
long a[1001][1001];
int main() {
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;
    for (int j = 0; j < m; j++) {
      if (s[j] == '#') {
        a[i][j] = 1;
      }
    }
  }
  queue<pair<int, int> > q;
  q.push(make_pair(0, 0));
  dis[0][0] = 0;
  mark[0][0] = 1;
  while (q.size() != 0) {
    pair<int, int> u = q.front();
    q.pop();
    if (!u.second) {
      for (int j = 0; j < m; j++) {
        if (a[u.first][j] == 1 && mark[j][1] != 1) {
          q.push(make_pair(j, 1));
          dis[j][1] = dis[u.first][0] + 1;
          mark[j][1] = 1;
        }
      }
    } else {
      for (int j = 0; j < n; j++) {
        if (a[j][u.first] == 1 && mark[j][0] != 1) {
          q.push(make_pair(j, 0));
          dis[j][0] = dis[u.first][1] + 1;
          mark[j][0] = 1;
        }
      }
    }
  }
  if (mark[n - 1][0] == 0) {
    cout << "-1";
  } else {
    cout << dis[n - 1][0] << endl;
  }
  return 0;
}
