#include <bits/stdc++.h>
using namespace std;
int main() {
  int h, w, ans = 0, l[4] = {0, 0, 1, -1}, m[4] = {1, -1, 0, 0};
  cin >> h >> w;
  vector<vector<char>> maze(h, vector<char>(w));
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) cin >> maze[i][j];
  }
  function<int(int, int, int, int)> cost = [&](int sx, int sy, int gx, int gy) {
    vector<vector<int>> dist(h, vector<int>(w, -1));
    queue<pair<int, int>> que;
    dist[sx][sy] = 0;
    que.push(make_pair(sx, sy));
    while (!que.empty()) {
      pair<int, int> d = que.front();
      int x, y;
      tie(x, y) = d;
      que.pop();
      for (int i = 0; i < 4; i++) {
        if (x + l[i] < 0 || h <= x + l[i]) continue;
        if (y + m[i] < 0 || w <= y + m[i]) continue;
        if (maze[x + l[i]][y + m[i]] == '#') continue;
        if (dist[x + l[i]][y + m[i]] != -1) continue;
        dist[x + l[i]][y + m[i]] = dist[x][y] + 1;
        que.push(make_pair(x + l[i], y + m[i]));
      }
    }
    return dist[gx][gy];
  };
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      for (int k = 0; k < h; k++) {
        for (int p = 0; p < w; p++) {
          ans = max(ans, cost(i, j, k, p));
        }
      }
    }
  }
  cout << ans << endl;
}
