#include <bits/stdc++.h>
using namespace std;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int H, W;
  cin >> H >> W;
  vector<string> S(H);
  for (int i = 0; i < (H); ++i) cin >> S[i];
  int res = 0;
  int dh[] = {1, 0, -1, 0};
  int dw[] = {0, 1, 0, -1};
  for (int i = 0; i < (H); ++i)
    for (int j = 0; j < (H); ++j) {
      if (S[i][j] == '#') continue;
      vector<vector<int>> dis(H, vector<int>(W, -1));
      dis[i][j] = 0;
      queue<pair<int, int>> qu;
      qu.emplace(i, j);
      while (!qu.empty()) {
        int k, l;
        tie(k, l) = qu.front();
        qu.pop();
        for (int m = 0; m < (4); ++m) {
          int y = k + dh[m];
          int x = l + dw[m];
          if (y >= 0 && y < H && x >= 0 && x < W && S[y][x] == '.' &&
              dis[y][x] < 0) {
            dis[y][x] = dis[k][l] + 1;
            res = max(res, dis[y][x]);
            qu.emplace(y, x);
          }
        }
      }
    }
  cout << res << endl;
  return 0;
}
