#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<vector<bool>> mat(21, vector<bool>(21, false));
vector<vector<bool>> flag(21, vector<bool>(21, false));
vector<vector<bool>> flagb(21, vector<bool>(21, false));
vector<vector<int>> flag2(21, vector<int>(21, 99999999));
vector<vector<int>> flag2b(21, vector<int>(21, 99999999));
int gy, gx, maxn = 0, minn = 999999;
bool flag3[21][21][21][21];
bool dame = false;
int func(int y, int x, int cnt) {
  if (dame == true) {
    return 0;
  }
  if (y < 0 || x < 0 || y >= H || x >= W) {
    return 0;
  }
  if (flag2[y][x] <= cnt) {
    return 0;
  }
  if (mat[y][x] == true) {
    return 0;
  }
  if (cnt >= minn) {
    return 0;
  }
  if (y == gy && x == gx) {
    if (cnt < minn) {
      minn = cnt;
    }
    if (cnt <= maxn) {
      dame = true;
    }
    return 0;
  }
  flag2[y][x] = cnt;
  func(y - 1, x, cnt + 1);
  func(y + 1, x, cnt + 1);
  func(y, x - 1, cnt + 1);
  func(y, x + 1, cnt + 1);
  return 0;
}
signed main() {
  memset(flag3, 0, sizeof(flag3));
  cin >> H >> W;
  for (int i = 0; i < H; i++) {
    string s;
    cin >> s;
    for (int j = 0; j < s.length(); j++) {
      if (s[j] == '#') {
        mat[i][j] = true;
      }
    }
  }
  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;
          if (flag3[i][j][k][t] == true) continue;
          if (mat[i][j] == true) continue;
          if (mat[k][t] == true) continue;
          flag3[i][j][k][t] = true;
          flag3[k][t][i][j] = true;
          gy = k;
          gx = t;
          func(i, j, 0);
          if (minn > maxn) {
            maxn = minn;
          }
          minn = 9999999;
          flag2 = flag2b;
          dame = false;
        }
      }
    }
  }
  cout << maxn << endl;
  return 0;
}
