#include <bits/stdc++.h>
using namespace std;
int pm[4][2] = {{0, -1}, {-1, 0}, {0, 1}, {1, 0}};
int main() {
  int h, w;
  cin >> h >> w;
  vector<string> vec(h);
  for (int i = 0; i < h; i++)
    for (int j = 0; j < w; j++) cin >> vec[i][j];
  long long ans = 0;
  for (int i = 0; i < h; i++)
    for (int j = 0; j < w; j++) {
      if (vec[i][j] == '#') continue;
      for (int k = 0; k < h; k++)
        for (int l = 0; l < w; l++) {
          if (vec[k][l] == '#') continue;
          vector<int> dist(h * w, -1);
          queue<int> que;
          dist[i * w + j] = 0;
          que.push(i * w + j);
          while (!que.empty()) {
            int v = que.front() / w, u = que.front() % w;
            que.pop();
            for (auto e : pm) {
              if (dist[(e[0] + v) * w + e[1] + u] != -1) continue;
              if (e[0] + v < 0 || e[1] + u < 0 || e[0] + v >= h ||
                  e[1] + u >= w || vec[e[0] + v][e[1] + u] == '#')
                continue;
              dist[(e[0] + v) * w + e[1] + u] = dist[v * w + u] + 1;
              que.push((e[0] + v) * w + e[1] + u);
            }
          }
          if (ans < dist[k * w + l]) ans = dist[k * w + l];
        }
    }
  cout << ans;
}
