#include <bits/stdc++.h>
using namespace std;
const int INF = 1 << 30;
int main() {
  int h, w;
  char maps[100][100];
  cin >> h >> w;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      cin >> maps[i][j];
    }
  }
  int maxim = 0;
  int dx[4] = {0, 1, 0, -1};
  int dy[4] = {-1, 0, 1, 0};
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (maps[j][i] != '#') {
        int sx = j, sy = i;
        int dist[100][100];
        for (int k = 0; k < h; k++) {
          for (int l = 0; l < w; l++) {
            dist[k][l] = INF;
          }
        }
        queue<pair<int, int> > que;
        que.push(pair<int, int>(sx, sy));
        dist[sy][sx] = 0;
        while (!que.empty()) {
          pair<int, int> now = que.front();
          que.pop();
          int x = now.first;
          int y = now.second;
          for (int k = 0; k < 4; k++) {
            int nx = x + dx[k];
            int ny = y + dy[k];
            if (0 <= nx && nx < w && 0 <= ny && ny < h && maps[ny][nx] != '#' &&
                dist[ny][nx] > dist[y][x]) {
              dist[ny][nx] = dist[y][x] + 1;
              maxim = max(dist[ny][nx], maxim);
              que.push(pair<int, int>(nx, ny));
            }
          }
        }
      }
    }
  }
  cout << maxim << endl;
  return (0);
}
