#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const int INF = 1000000000;
using Graph = vector<vector<int>>;
int H, W;
char field[30][30];
int sx, sy;
long long d[30][30];
long long depth;
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
long long bfs() {
  queue<pair<int, int>> que;
  for (int i = 0; i < H; i++)
    for (int j = 0; j < W; j++) d[i][j] = INF;
  que.push(pair<int, int>(sx, sy));
  d[sx][sy] = 0;
  depth = 0;
  while (que.size()) {
    pair<int, int> p = que.front();
    que.pop();
    for (int i = 0; i < 4; i++) {
      int nx = p.first + dx[i], ny = p.second + dy[i];
      if (0 <= nx && nx < H && 0 <= ny && ny < W && field[nx][ny] == '.' &&
          d[nx][ny] == INF) {
        que.push(pair<int, int>(nx, ny));
        d[nx][ny] = d[p.first][p.second] + 1;
      }
    }
  }
  long long res = 0;
  for (int i = 0; i < H; i++)
    for (int j = 0; j < W; j++) {
      if (d[i][j] == INF) continue;
      res = max(d[i][j], res);
    }
  return res;
}
int main() {
  cin >> H >> W;
  for (int i = 0; i < H; i++)
    for (int j = 0; j < W; j++) cin >> field[i][j];
  long long res = 0;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      sx = i;
      sy = j;
      res = max(res, bfs());
    }
  }
  cout << res << endl;
}
