#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e9 + 7;
long long int int_pow(long long int base, long long int exp) {
  long long int result = 1;
  while (exp) {
    if (exp & 1) result *= base;
    exp /= 2;
    base *= base;
  }
  return result;
}
vector<long long int> v[2005];
bool mark[2005];
long long int d[2005];
queue<long long int> q;
void enque(long long int s, long long int dist) {
  mark[s] = 1;
  q.push(s);
  d[s] = dist + 1;
}
void BFS(long long int s) {
  enque(s, 0);
  while (!q.empty()) {
    long long int x = q.front();
    q.pop();
    for (long long int y : v[x]) {
      if (!mark[y]) enque(y, d[x]);
    }
  }
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long int n, m;
  cin >> n >> m;
  char c;
  for (long long int i = 1; i <= n; i++) {
    for (long long int j = 1; j <= m; j++) {
      cin >> c;
      if (c == '#') v[i].push_back(n + j), v[n + j].push_back(i);
    }
  }
  BFS(1);
  cout << d[n] - 1;
}
