#include <bits/stdc++.h>
using namespace std;
int H, W;
string S;
bool map[21][21];
bool visited[21][21];
int mv_max = 0;
int sx, sy, gx, gy;
int map_rec(int y, int x, int d) {
  int d_min = 1000000000, tmp;
  if (y == gy && x == gx) {
    return d;
  }
  visited[y][x] = true;
  if (y > 0 && map[y - 1][x] && !visited[y - 1][x]) {
    tmp = map_rec(y - 1, x, d + 1);
    if (tmp < d_min) {
      d_min = tmp;
    }
  }
  if (y < H - 1 && map[y + 1][x] && !visited[y + 1][x]) {
    tmp = map_rec(y + 1, x, d + 1);
    if (tmp < d_min) {
      d_min = tmp;
    }
  }
  if (x > 0 && map[y][x - 1] && !visited[y][x - 1]) {
    tmp = map_rec(y, x - 1, d + 1);
    if (tmp < d_min) {
      d_min = tmp;
    }
  }
  if (x < W - 1 && map[y][x + 1] && !visited[y][x + 1]) {
    tmp = map_rec(y, x + 1, d + 1);
    if (tmp < d_min) {
      d_min = tmp;
    }
  }
  visited[y][x] = false;
  return d_min;
}
int main() {
  int ans = 0, tmp;
  cin >> H >> W;
  for (int i = 0; i < H; i++) {
    cin >> S;
    for (int j = 0; j < W; j++) {
      if (S[j] == '.') {
        map[i][j] = true;
      } else {
        map[i][j] = false;
      }
      visited[i][j] = false;
    }
  }
  for (sy = 0; sy < H; sy++) {
    for (sx = 0; sx < W; sx++) {
      for (gy = 0; gy < H; gy++) {
        for (gx = 0; gx < W; gx++) {
          if (!map[sy][sx] || !map[gy][gx]) {
            continue;
          }
          tmp = map_rec(sy, sx, 0);
          if (tmp > ans) {
            ans = tmp;
          }
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}
