#include <bits/stdc++.h>
using namespace std;
int dist[55][55];
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
int H, W;
char maze[51][51];
int search(int sx, int sy, int gx, int gy) {
  queue<pair<int, int> > que;
  for (int i = 0; i < H; i++)
    for (int j = 0; j < W; j++) dist[i][j] = -1;
  que.push(pair<int, int>(sx, sy));
  dist[sx][sy] = 0;
  while (!que.empty()) {
    pair<int, int> p = que.front();
    que.pop();
    if (p.first == gx && p.second == gy) return dist[gx][gy];
    for (int i = 0; i < 4; i++) {
      int nx = p.first + dx[i], ny = p.second + dy[i];
      if (0 <= nx && nx < H && 0 <= ny && ny < W && maze[nx][ny] != '#' &&
          dist[nx][ny] == -1) {
        que.push(pair<int, int>(nx, ny));
        dist[nx][ny] = dist[p.first][p.second] + 1;
      }
    }
  }
  return 0;
}
int main() {
  cin >> H >> W;
  for (int i = 0; i < (int)(H); i++) {
    for (int j = 0; j < (int)(W); j++) {
      cin >> maze[i][j];
    }
  }
  int ans = 0;
  for (int sx = 0; sx < (int)(H); sx++) {
    for (int sy = 0; sy < (int)(W); sy++) {
      for (int gx = 0; gx < (int)(H); gx++) {
        for (int gy = 0; gy < (int)(W); gy++) {
          ans = max(ans, search(sx, sy, gx, gy));
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}
