#include <bits/stdc++.h>
using namespace std;
int H, W;
void BFS(vector<vector<char>> &S, queue<vector<int>> &q, int *max) {
  int count = q.front()[0];
  int h = q.front()[1];
  int w = q.front()[2];
  *max = count;
  S[h][w] = '#';
  q.pop();
  if (h > 0 && S[h - 1][w] != '#') q.push({count + 1, h - 1, w});
  if (h < H - 1 && S[h + 1][w] != '#') q.push({count + 1, h + 1, w});
  if (w > 0 && S[h][w - 1] != '#') q.push({count + 1, h, w - 1});
  if (w < W - 1 && S[h][w + 1] != '#') q.push({count + 1, h, w + 1});
  if (!q.empty()) BFS(S, q, max);
}
int main() {
  cin >> H >> W;
  vector<vector<char>> S(H, vector<char>(W));
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) cin >> S[i][j];
  }
  vector<vector<char>> s = S;
  int ans = 0;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      if (S[i][j] != '#') {
        int max = 0;
        queue<vector<int>> q;
        q.push({0, i, j});
        BFS(s, q, &max);
        if (ans < max) ans = max;
        s = S;
      }
    }
  }
  cout << ans;
}
