#include <bits/stdc++.h>
using namespace std;
const int maxH = 25, maxW = 25;
int H, W;
char grid[maxH][maxW + 1];
int dx[4] = {-1, 0, 1, 0}, dy[4] = {0, -1, 0, 1};
bool used[maxH][maxW];
int dist[maxH][maxW][maxH][maxW];
void bfs(int x, int y, int dist[maxH][maxW]) {
  queue<int> qx, qy;
  qx.push(x);
  qy.push(y);
  while (!qx.empty()) {
    int x = qx.front();
    qx.pop();
    int y = qy.front();
    qy.pop();
    used[x][y] = true;
    for (int i = 0; i < 4; i++) {
      int x2 = x + dx[i], y2 = y + dy[i];
      if (x2 >= 0 && x2 < H && y2 >= 0 && y2 < W && grid[x2][y2] == '.' &&
          !used[x2][y2]) {
        qx.push(x2);
        qy.push(y2);
        dist[x2][y2] = dist[x][y] + 1;
      }
    }
  }
}
void input() {
  cin >> H >> W;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      cin >> grid[i][j];
    }
  }
}
int main() {
  input();
  for (int x = 0; x < H; x++) {
    for (int y = 0; y < W; y++) {
      if (grid[x][y] == '.') {
        memset(used, false, sizeof(used));
        bfs(x, y, dist[x][y]);
      }
    }
  }
  int res = 0;
  for (int x1 = 0; x1 < H; x1++) {
    for (int y1 = 0; y1 < W; y1++) {
      for (int x2 = 0; x2 < H; x2++) {
        for (int y2 = 0; y2 < W; y2++) {
          res = max(res, dist[x1][y1][x2][y2]);
        }
      }
    }
  }
  cout << res << endl;
}
