#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007LL;
const string alpha = "abcdefghijklmnopqrstuvwxyz";
int main() {
  int h, w;
  cin >> h >> w;
  char s[h + 2][w + 2];
  for (int i = 0; i < h + 2; i++)
    for (int j = 0; j < w + 2; j++) s[i][j] = '#';
  for (int i = 0; i < h; i++)
    for (int j = 0; j < w; j++) cin >> s[i + 1][j + 1];
  int ta[h + 2][w + 2];
  bool visited[h + 2][w + 2];
  int dx[4] = {1, 0, -1, 0};
  int dy[4] = {0, 1, 0, -1};
  int ans = 0;
  for (int i = 0; i < h; i++)
    for (int j = 0; j < w; j++) {
      if (s[i + 1][j + 1] != '#') {
        queue<pair<int, int> > que = {};
        que.push(make_pair(i + 1, j + 1));
        for (int p = 0; p < h + 2; p++)
          for (int q = 0; q < w + 2; q++) ta[p][q] = 0;
        for (int p = 0; p < h + 2; p++)
          for (int q = 0; q < w + 2; q++) visited[p][q] = false;
        while (!que.empty()) {
          pair<int, int> now = que.front();
          int nowx = now.first;
          int nowy = now.second;
          visited[nowx][nowy] = true;
          que.pop();
          for (int k = 0; k < 4; k++) {
            if (s[nowx + dx[k]][nowy + dy[k]] == '.' &&
                (!visited[nowx + dx[k]][nowy + dy[k]])) {
              ta[nowx + dx[k]][nowy + dy[k]] = ta[nowx][nowy] + 1;
              que.push(make_pair(nowx + dx[k], nowy + dy[k]));
            }
          }
        }
        for (int p = 0; p < h + 2; p++)
          for (int q = 0; q < w + 2; q++) ans = max(ans, ta[p][q]);
      }
    }
  cout << ans << endl;
}
