#include <bits/stdc++.h>
using namespace std;
void warfl(vector<vector<int> > &dist, int n) {
  for (int k = 0; k < n; k++) {
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
      }
    }
  }
  return;
}
int main() {
  int H, W;
  char S[20][20];
  cin >> H >> W;
  int n = H * W;
  vector<vector<int> > dist(n, vector<int>(n, 1000));
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      cin >> S[i][j];
    }
  }
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      int idx = i * W + j;
      if (j + 1 < W && S[i][j + 1] == '.') {
        dist[idx][idx + 1] = 1;
        dist[idx + 1][idx] = 1;
      }
      if (i + 1 < H && S[i + 1][j] == '.') {
        dist[idx][idx + W] = 1;
        dist[idx + W][idx] = 1;
      }
    }
  }
  warfl(dist, n);
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      if (S[i][j] == '#') {
        int idx = i * W + j;
        for (int k = 0; k < n; k++) {
          dist[idx][k] = 0;
          dist[k][idx] = 0;
        }
      }
    }
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      ans = max(ans, dist[i][j]);
    }
  }
  cout << ans << endl;
  return 0;
}
