#include <bits/stdc++.h>
using namespace std;
int mx4[] = {0, 1, 0, -1};
int my4[] = {1, 0, -1, 0};
int main() {
  int h, w;
  cin >> h >> w;
  vector<vector<char>> s(h + 2, vector<char>(w + 2));
  for (int i = 0; i < (h + 2); i++)
    for (int j = 0; j < (w + 2); j++) s[i][j] = 'e';
  for (int i = 1; i <= h; i++)
    for (int j = 1; j <= w; j++) cin >> s[i][j];
  queue<pair<int, int>> que;
  int ANS = 1;
  for (int i = 1; i <= h; i++)
    for (int j = 1; j <= w; j++) {
      vector<vector<int>> ans(h + 2, vector<int>(w + 2));
      for (int l = 0; l < (h + 2); l++)
        for (int m = 0; m < (w + 2); m++) ans[l][m] = -1;
      for (int l = 1; l <= h; l++)
        for (int m = 1; m <= w; m++) ans[l][m] = -3;
      ans[i][j] = 0;
      que.push(make_pair(i, j));
      if (s[i][j] != '#') {
        while (que.size()) {
          pair<int, int> p = que.front();
          que.pop();
          for (int k = 0; k < (4); k++) {
            int py = p.first + my4[k];
            int px = p.second + mx4[k];
            if (s[py][px] == '.' && ans[py][px] == -3) {
              que.push(make_pair(py, px));
              ans[py][px] = ans[p.first][p.second] + 1;
            }
          }
        }
        for (int x = 1; x <= h; x++)
          for (int y = 1; y <= w; y++) {
            ANS = max(ANS, ans[x][y]);
          }
      }
    }
  cout << ANS << endl;
}
