#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
const long long INF = 1000000000000000000;
int H, W;
int d[21][21];
string S[21];
int vx[] = {1, 0, -1, 0};
int vy[] = {0, 1, 0, -1};
struct point {
  int X, Y;
};
void bfs(int x, int y) {
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      if (S[i][j] == '.') d[i][j] = mod;
    }
  }
  d[y][x] = 0;
  queue<point> que;
  que.push({x, y});
  while (!que.empty()) {
    point now = que.front();
    que.pop();
    for (int i = 0; i < 4; i++) {
      int nx = now.X + vx[i];
      int ny = now.Y + vy[i];
      if (nx < 0 || nx >= W || ny < 0 || ny >= H || S[ny][nx] == '#' ||
          d[ny][nx] != mod)
        continue;
      d[ny][nx] = d[now.Y][now.X] + 1;
      que.push({nx, ny});
    }
  }
}
int main() {
  cin >> H >> W;
  for (int i = 0; i < H; i++) cin >> S[i];
  int ans = 0;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      bfs(j, i);
      for (int k = 0; k < H; k++) {
        for (int l = 0; l < W; l++) {
          ans = max(ans, d[k][l]);
        }
      }
    }
  }
  cout << ans << endl;
}
