#include <bits/stdc++.h>
using namespace std;
vector<string> m;
int h, w;
int Ans[30][30];
int ove[] = {0, 1, 0, -1};
int Move[] = {1, 0, -1, 0};
int main() {
  cin >> h >> w;
  m.resize(h);
  for (int i = 0; i < h; i++) cin >> m[i];
  int ans = 0;
  queue<pair<int, int> > next;
  for (int i = 0; i < h; i++)
    for (int j = 0; j < w; j++) {
      if (m[i][j] == '#') continue;
      for (int k = 0; k < h; k++)
        for (int l = 0; l < w; l++) Ans[k][l] = -1;
      next.push(pair<int, int>(i, j));
      Ans[i][j] = 0;
      while (!next.empty()) {
        pair<int, int> ne;
        ne = next.front();
        next.pop();
        int nowi = ne.first;
        int nowj = ne.second;
        for (int k = 0; k < 4; k++) {
          int ni = ne.first + ove[k];
          int nj = ne.second + Move[k];
          if (ni >= h || ni < 0 || nj >= w || nj < 0) continue;
          if (Ans[ni][nj] > 0) continue;
          if (m[ni][nj] == '#') continue;
          next.push(pair<int, int>(ni, nj));
          Ans[ni][nj] = Ans[nowi][nowj] + 1;
        }
      }
      for (int k = 0; k < h; k++)
        for (int l = 0; l < w; l++) ans = max(ans, Ans[k][l]);
    }
  cout << ans << endl;
  return 0;
}
