#include <bits/stdc++.h>
using namespace std;
const int INF = 40;
int sx, sy;
int gx, gy;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
int h, w, ans = 0;
int main() {
  cin >> h >> w;
  char maze[w][h];
  int d[w][h];
  string S;
  for (int i = 0; i < h; i++) {
    cin >> S;
    for (int j = 0; j < w; j++) {
      maze[j][i] = S[j];
    }
  }
  queue<pair<int, int> > que;
  for (int sy = 0; sy < h; ++sy) {
    for (int sx = 0; sx < w; ++sx) {
      for (int initi = 0; initi < h; initi++)
        for (int initj = 0; initj < w; initj++) d[initj][initi] = INF;
      que.push(pair<int, int>(sx, sy));
      d[sx][sy] = 0;
      while (que.size()) {
        pair<int, int> p = que.front();
        que.pop();
        for (int i = 0; i < 4; i++) {
          int nx = p.first + dx[i], ny = p.second + dy[i];
          if (0 <= nx && nx < w && 0 <= ny && ny < h && maze[nx][ny] != '#' &&
              d[nx][ny] == INF) {
            que.push(pair<int, int>(nx, ny));
            d[nx][ny] = d[p.first][p.second] + 1;
          }
        }
      }
      for (int i = 0; i < (w); i++)
        for (int j = 0; j < (h); j++)
          if (d[i][j] != INF) ans = max(ans, d[i][j]);
    }
  }
  cout << ans << endl;
  return 0;
}
