#include <bits/stdc++.h>
using namespace std;
string S;
bool Map[25][25], Vis[25][25];
int Pos[] = {1, -1, 0, 0, 0, 0, -1, 1}, H, W, Max = 0;
struct Poi {
  int x, y, dis = 0;
};
queue<Poi> Q;
void BFS(int x, int y) {
  int dx, dy;
  for (int i = 1; i <= H; i++)
    for (int j = 1; j <= W; j++) Vis[i][j] = false;
  Poi t, k;
  t.x = x, t.y = y, t.dis = 0;
  Q.push(t);
  while (Q.size()) {
    t = Q.front();
    Q.pop();
    for (int i = 0; i < 4; i++) {
      dx = t.x + Pos[i], dy = t.y + Pos[i + 4];
      if (dx >= 1 && dx <= H && dy >= 1 && dy <= W && !Vis[dx][dy] &&
          Map[dx][dy]) {
        Vis[dx][dy] = true;
        k.x = dx, k.y = dy, k.dis = t.dis + 1;
        if (k.dis > Max) Max = k.dis;
        Q.push(k);
      }
    }
  }
}
int main() {
  scanf("%d%d", &H, &W);
  for (int i = 1; i <= H; i++) {
    cin >> S;
    for (int j = 1; j <= W; j++) {
      if (S[j - 1] == '.')
        Map[i][j] = 1;
      else
        Map[i][j] = 0;
    }
  }
  for (int i = 1; i <= H; i++) {
    for (int j = 1; j <= W; j++) {
      if (Map[i][j]) BFS(i, j);
    }
  }
  printf("%d\n", Max);
  return 0;
}
