#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] == '#') continue;
      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] + 1) {
            dist[ny][nx] = dist[y][x] + 1;
            que.push(pair<int, int>(nx, ny));
          }
        }
      }
      for (int k = 0; k < h; k++) {
        for (int l = 0; l < w; l++) {
          if (maps[k][l] != '#') {
            maxim = max(dist[k][l], maxim);
          }
        }
      }
    }
  }
  cout << maxim << endl;
  return (0);
}
