#include <bits/stdc++.h>
using namespace std;
int ir, ic, grid[3050][3050];
bool vis[3050];
vector<int> adj[3050];
int main() {
  scanf("%d%d", &ir, &ic);
  for (int r = 1; r <= ir; r++) {
    string str;
    cin >> str;
    for (int c = 0; c < ic; c++) {
      int keep = 0;
      if (str[c] == '#') keep = 1;
      grid[r][c + 1] = keep;
    }
  }
  for (int c = 1; c <= ic; c++) {
    for (int r = 1; r <= ir; r++) {
      if (grid[r][c]) {
        adj[r].push_back(c + ir);
        adj[c + ir].push_back(r);
      }
    }
  }
  queue<pair<int, int> > q;
  q.push(make_pair(1, 0));
  int sol = -1;
  while (!q.empty()) {
    pair<int, int> curr = q.front();
    q.pop();
    int cn = curr.first, cd = curr.second;
    if (cn == ir) {
      sol = cd;
      break;
    }
    if (vis[cn]) continue;
    vis[cn] = true;
    for (int next : adj[cn]) {
      int nd = cd + 1;
      q.push(make_pair(next, nd));
    }
  }
  printf("%d\n", sol);
}
