#include <bits/stdc++.h>
using namespace std;
char arr[100][100];
long long arr1[100][100];
long long mn;
void minz(int a, int b, int c, int d, int ans) {
  arr1[a][b] = 1;
  if (a == c && b == d) {
    if (mn > ans) {
      mn = ans;
    }
    arr1[a][b] = 0;
    return;
  }
  if (arr[a + 1][b] == '.' && arr1[a + 1][b] == 0) {
    minz(a + 1, b, c, d, ans + 1);
  }
  if (arr[a - 1][b] == '.' && arr1[a - 1][b] == 0) {
    minz(a - 1, b, c, d, ans + 1);
  }
  if (arr[a][b + 1] == '.' && arr1[a][b + 1] == 0) {
    minz(a, b + 1, c, d, ans + 1);
  }
  if (arr[a][b - 1] == '.' && arr1[a][b - 1] == 0) {
    minz(a, b - 1, c, d, ans + 1);
  }
  arr1[a][b] = 0;
  return;
}
int main() {
  long long h, w, i, j, k, i1, j1, mx;
  mx = -1;
  cin >> h >> w;
  for (i = 5; i < h + 5; i++) {
    for (j = 5; j < w + 5; j++) {
      cin >> arr[i][j];
    }
  }
  for (i = 5; i < h + 5; i++) {
    for (j = 5; j < w + 5; j++) {
      if (arr[i][j] == '.') {
        break;
      }
    }
  }
  for (i1 = h + 4; i1 >= 5; i1--) {
    for (j1 = w + 4; j1 >= 5; j1--) {
      if (arr[i1][j1] == '.') {
        break;
      }
    }
  }
  minz(i, j, i1, j1, 0);
  cout << mn << endl;
}
