#include <bits/stdc++.h>
using namespace std;
int main() {
  int h, w;
  cin >> h >> w;
  string s[w];
  for (int i = 0; i < h; i++) cin >> s[i];
  int dx[] = {0, 1, 0, -1};
  int dy[] = {1, 0, -1, 0};
  int mx = 0;
  for (int i = 0; i < h; i++)
    for (int j = 0; j < w; j++) {
      if (s[i][j] == '#') continue;
      queue<pair<int, int> > q;
      q.push(pair<int, int>(i, j));
      int dis[h][w];
      for (int k = 0; k < h; k++)
        for (int l = 0; l < w; l++) dis[k][l] = 0;
      while (q.size() > 0) {
        pair<int, int> p = q.front();
        q.pop();
        for (int k = 0; k < 4; k++) {
          int x = p.first, y = p.second;
          int nx = x + dx[k];
          int ny = y + dy[k];
          if (0 <= nx && nx < h && 0 <= ny && ny < w && dis[nx][ny] == 0 &&
              s[nx][ny] == '.') {
            dis[nx][ny] = dis[x][y] + 1;
            mx = max(mx, dis[nx][ny]);
            q.push(pair<int, int>(nx, ny));
          }
        }
      }
    }
  cout << mx << endl;
}
