#include <bits/stdc++.h>
using namespace std;
const long double EPS = 1e-10;
const int INF = (int)(2e9);
const long long mod = (int)(1e+9 + 7);
const int N = (int)(2e3);
int days_month[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
vector<int> vec[N + 1];
int dist[N + 1];
void bfs(int st) {
  for (int i = 0; i < N + 1; i++) {
    dist[i] = INF;
  }
  dist[st] = 0;
  queue<int> q;
  q.push(st);
  while (!q.empty()) {
    int a = q.front();
    q.pop();
    for (int b : vec[a]) {
      if (dist[b] > 1 + dist[a]) {
        dist[b] = 1 + dist[a];
        q.push(b);
      }
    }
  }
}
int main() {
  int n, m;
  cin >> n >> m;
  char ch;
  for (int i = (1); i <= (n); i++) {
    for (int j = (1); j <= (m); j++) {
      scanf(" %c", &ch);
      if (ch == '#') {
        vec[j + n].push_back(i);
        vec[i].push_back(j + n);
      }
    }
  }
  bfs(n);
  int ans = dist[1];
  if (ans == INF) return cout << -1, 0;
  ;
  cout << ans;
  return 0;
}
