#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
const int INF = 100000;
int H, W;
int posToIndex(int h, int w) { return h * W + w; }
int dp[400][400];
int main() {
  cin.tie(0);
  ios::sync_with_stdio(0);
  cin >> H >> W;
  vector<string> S(H);
  for (int i = 0; i < (H); ++i) cin >> S[i];
  for (int s = 0; s < (400); ++s)
    for (int d = 0; d < (400); ++d) {
      if (s != d) {
        dp[s][d] = INF;
      }
    }
  for (int h = 0; h < (H); ++h)
    for (int w = 0; w < (W); ++w) {
      if (S[h][w] == '#') {
        int i = posToIndex(w, h);
        for (int j = 0; j < (400); ++j) {
          dp[i][j] = INF;
          dp[j][i] = INF;
        }
      }
    }
  bool prog = false;
  do {
    prog = false;
    for (int sy = 0; sy < (H); ++sy)
      for (int sx = 0; sx < (W); ++sx) {
        if (S[sy][sx] == '.') {
          int is = posToIndex(sy, sx);
          for (int dy = 0; dy < (H); ++dy)
            for (int dx = 0; dx < (W); ++dx) {
              if (S[dy][dx] == '.') {
                int id = posToIndex(dy, dx);
                if (0 < dy) {
                  int c = dp[is][posToIndex(dy - 1, dx)] + 1;
                  if (c < dp[is][id]) {
                    dp[is][id] = c;
                    prog = true;
                  }
                }
                if (0 < dx) {
                  int c = dp[is][posToIndex(dy, dx - 1)] + 1;
                  if (c < dp[is][id]) {
                    dp[is][id] = c;
                    prog = true;
                  }
                }
                if (dx < W - 1) {
                  int c = dp[is][posToIndex(dy, dx + 1)] + 1;
                  if (c < dp[is][id]) {
                    dp[is][id] = c;
                    prog = true;
                  }
                }
                if (dy < H - 1) {
                  int c = dp[is][posToIndex(dy + 1, dx)] + 1;
                  if (c < dp[is][id]) {
                    dp[is][id] = c;
                    prog = true;
                  }
                }
              }
            }
        }
      }
  } while (prog);
  int ans = 0;
  for (int s = 0; s < (400); ++s)
    for (int d = 0; d < (400); ++d) {
      int c = dp[s][d];
      if (c < 400) {
        ans = max(ans, c);
      }
    }
  cout << ans << endl;
  return 0;
}
