#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<char>>;
void dfs(Graph T, vector<vector<int>> &U, int i, int j, int l) {
  if (T[i][j] == '#') return;
  T[i][j] = '#', l++;
  if (U[i][j] > l) U[i][j] = l;
  dfs(T, U, i + 1, j, l);
  dfs(T, U, i, j + 1, l);
  dfs(T, U, i - 1, j, l);
  dfs(T, U, i, j - 1, l);
}
int main() {
  int H, W;
  cin >> H >> W;
  char a;
  Graph S(H + 2, vector<char>(W + 2, '#')), T(H + 2, vector<char>(W + 2, '#'));
  vector<vector<int>> U(H + 2, vector<int>(W + 2, 400)),
      V(H + 2, vector<int>(W + 2, -1));
  for (int i = 1; i <= H; ++i) {
    for (int j = 1; j <= W; ++j) {
      cin >> a;
      S[i][j] = a;
    }
  }
  T = S;
  for (int i = 1; i <= H; ++i) {
    for (int j = 1; j <= W; ++j) {
      if (T[i][j] == '#') continue;
      dfs(T, U, i, j, -1);
      T = S;
      for (int k = 1; k <= H; ++k) {
        for (int l = 1; l <= W; ++l) {
          if (U[k][l] == 400) U[k][l] = -1;
          if (V[k][l] < U[k][l]) V[k][l] = U[k][l];
        }
      }
      U.assign(H + 2, vector<int>(W + 2, 400));
    }
  }
  int ans = 0;
  for (int i = i; i <= H; ++i) {
    for (int j = 1; j <= W; ++j) {
      ans = max(ans, V[i][j]);
    }
  }
  cout << ans << endl;
}
