#include <bits/stdc++.h>
using namespace std;
int main() {
  int h, w;
  cin >> h >> w;
  char b[h][w];
  for (int i = 0; i < h; i++)
    for (int j = 0; j < w; j++) cin >> b[i][j];
  int dh[4] = {-1, 1, 0, 0};
  int dw[4] = {0, 0, 1, -1};
  int ans = 0;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (b[i][j] == '.') {
        queue<pair<int, int>> q;
        q.push(make_pair(i, j));
        vector<vector<bool>> visited(h, vector<bool>(w, 0));
        int step[h][w];
        step[i][j] = 0;
        int maxp = 0;
        while (!q.empty()) {
          pair<int, int> cr = q.front();
          maxp = max(maxp, step[cr.first][cr.second]);
          q.pop();
          for (int i = 0; i < 4; i++) {
            int nh = cr.first + dh[i];
            int nw = cr.second + dw[i];
            if (nh > h - 1 || nh < 0 || nw > w - 1 || nw < 0 ||
                b[nh][nw] == '#' || visited[nh][nw] == 1)
              continue;
            else {
              q.push(make_pair(nh, nw));
              visited[nh][nw] = 1;
              step[nh][nw] = step[cr.first][cr.second] + 1;
            }
          }
        }
        ans = max(ans, maxp);
      }
    }
  }
  cout << ans << endl;
}
