#include <bits/stdc++.h>
using namespace std;
bool used[50][50];
string s[50];
int r, c, sx, sy, gx, gy;
int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
int d[50][50];
int bfs(int x, int y) {
  queue<pair<int, int> > P;
  d[x][y] = 0;
  P.push(make_pair(x, y));
  while (!P.empty()) {
    pair<int, int> p = P.front();
    P.pop();
    int nx = p.first, ny = p.second;
    used[nx][ny] = true;
    for (int r = 0; r < 4; r++) {
      int tx = nx + dx[r], ty = ny + dy[r];
      if (s[tx][ty] == '#' || used[tx][ty]) continue;
      d[tx][ty] = d[nx][ny] + 1;
      used[tx][ty] = true;
      P.push(make_pair(tx, ty));
    }
  }
  return d[gx][gy];
}
int main() {
  int ans = 400, temp;
  cin >> r >> c;
  for (int i = 0; i < r; i++) cin >> s[i];
  for (int i = 0; i < r; i++) {
    gx = i;
    for (int j = 0; j < c; j++) {
      gy = j;
      for (int k = i; k < r; k++) {
        sx = k;
        for (int l = j; l < c; l++) {
          sy = l;
          if (i != k || j != 0) {
            if (d[i][j] != '#' && d[k][l] != '#') {
              temp = bfs(k, l);
              if (ans > temp) ans = temp;
            }
          }
        }
      }
    }
  }
  cout << ans << endl;
}
