#include <bits/stdc++.h>
using namespace std;
static const long long maxLL = (long long)1 << 62;
const long long MOD = 1000000007;
const long long INF = 1e18;
const double PI = 3.14159265359;
int ca[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int H, W;
vector<string> mat;
int flag[30][30];
int flag2[30][30];
int goaly, goalx, maxn = 99999999;
int maxy, maxx;
int maxy2, maxx2, maxn2 = 0;
int func(int y, int x, int cnt) {
  if (y < 0 || y >= H || x < 0 || x >= W) {
    return 0;
  }
  if (mat[y][x] == '#') {
    return 0;
  }
  if (y == goaly && x == goalx) {
    maxn = min(maxn, cnt);
    maxy = y;
    maxx = x;
    return 0;
  }
  if (flag[y][x] <= cnt) {
    return 0;
  }
  flag[y][x] = cnt;
  func(y + 1, x, cnt + 1);
  func(y, x + 1, cnt + 1);
  func(y - 1, x, cnt + 1);
  func(y, x - 1, cnt + 1);
}
signed main() {
  for (int i = 0; i < 30; i++) {
    for (int j = 0; j < 30; j++) {
      flag[i][j] = 99999999;
      flag2[i][j] = 99999999;
    }
  }
  cin >> H >> W;
  for (int i = 0; i < H; i++) {
    string s;
    cin >> s;
    mat.push_back(s);
  }
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      for (int k = 0; k < H; k++) {
        for (int t = 0; t < W; t++) {
          if (i == k && j == t) continue;
          goaly = k, goalx = t;
          func(i, j, 0);
          if (maxn > maxn2 && maxn < 99999999) {
            maxn2 = maxn;
            maxy2 = maxy;
            maxx2 = maxx;
          }
          maxn = 99999999;
          for (int i2 = 0; i2 < 30; i2++) {
            for (int j2 = 0; j2 < 30; j2++) {
              flag[i2][j2] = 99999999;
            }
          }
        }
      }
    }
  }
  cout << maxn2 << endl;
  return 0;
}
