#include <bits/stdc++.h>
using namespace std;
const int INF = 1 << 30;
int H, W;
char G[20][20];
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
int cost[20][20];
int f(int sy, int sx, int gy, int gx) {
  for (int i = 0; i < (int)(H); i++)
    for (int j = 0; j < (int)(W); j++) cost[i][j] = INF;
  cost[sy][sx] = 0;
  queue<pair<int, int> > Q;
  Q.push(make_pair(sx, sy));
  while (!Q.empty()) {
    int x = Q.front().first;
    int y = Q.front().second;
    Q.pop();
    for (int i = 0; i < (int)(4); i++) {
      int nx = x + dx[i];
      int ny = y + dy[i];
      if (!(0 <= nx && nx < W && 0 <= ny && ny < H)) continue;
      if (G[ny][nx] == '#') continue;
      if (cost[ny][nx] <= cost[y][x] + 1) continue;
      cost[ny][nx] = cost[y][x] + 1;
      if (nx == gx && ny == gy) return cost[ny][nx];
      Q.push(make_pair(nx, ny));
    }
  }
}
int main() {
  cin >> H >> W;
  for (int i = 0; i < (int)(H); i++)
    for (int j = 0; j < (int)(W); j++) cin >> G[i][j];
  int ans = 0;
  for (int i = 0; i < (int)(H); i++)
    for (int j = 0; j < (int)(W); j++)
      for (int p = 0; p < (int)(H); p++)
        for (int q = 0; q < (int)(W); q++) {
          if (G[i][j] == '.' && G[p][q] == '.') ans = max(ans, f(i, j, p, q));
        }
  cout << ans << endl;
}
