#include <bits/stdc++.h>
using namespace std;
int H, W;
char S[20][20];
int dx[4] = {-1, 1, 0, 0};
int dy[4] = {0, 0, 1, -1};
struct ichi {
  int y;
  int x;
  int depth;
};
queue<ichi> q;
int bfs(int s, int t, int h, int gx, int gy) {
  struct ichi start;
  start.x = t;
  start.y = s;
  start.depth = h;
  q.push(start);
  while (!q.empty()) {
    ichi now = q.front();
    q.pop();
    if (now.x == gx && now.y == gy) return now.depth;
    for (int i = 0; i < 4; i++) {
      ichi next = {now.y + dy[i], now.x + dx[i], now.depth + 1};
      if (next.y >= 0 && next.y < H && next.x >= 0 && next.x < W &&
          S[next.y][next.y] == '.') {
        q.push(next);
      }
    }
  }
}
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 a = 0; a < H; a++) {
    for (int b = 0; b < W; b++) {
      for (int c = 0; c < H; c++) {
        for (int d = 0; d < W; d++) {
          if (S[a][b] == '.') ans = max(ans, bfs(a, b, 0, c, d));
        }
      }
    }
  }
  cout << ans;
  return 0;
}
