#include <bits/stdc++.h>
using namespace std;
char s[20][20];
int check[20][20];
int h, w;
int bfs(int sy, int sx, int gy, int gx) {
  for (int i = 0; i < 20; i++) {
    for (int j = 0; j < 20; j++) {
      check[i][j] = -1;
    }
  }
  check[sy][sx] = 0;
  queue<int> memo;
  memo.push(sy);
  memo.push(sx);
  while (!memo.empty()) {
    int y = memo.front();
    memo.pop();
    int x = memo.front();
    memo.pop();
    int dy[4] = {0, 1, 0, -1}, dx[4] = {1, 0, -1, 0};
    for (int i = 0; i < 4; i++) {
      int ny = y + dy[i], nx = x + dx[i];
      if (ny < 0 || ny >= h || nx < 0 || nx >= w || s[ny][nx] == '#') continue;
      if (check[ny][nx] != -1) continue;
      check[ny][nx] = check[y][x] + 1;
      memo.push(ny);
      memo.push(nx);
    }
  }
  return check[gy][gx];
}
int main() {
  cin >> h >> w;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) cin >> s[i][j];
  }
  int ans = 0;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < h; j++) {
      if (s[i][h] == '#') continue;
      for (int p = 0; p < h; p++) {
        for (int q = 0; q < w; q++) {
          if ((s[p][q] == '#') || (i == p && j == q)) continue;
          ans = max(ans, bfs(i, j, p, q));
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}
