#include <bits/stdc++.h>
using namespace std;
int h, w;
string field[25];
bool f[25][25];
int n[25][25];
void bfs(int x, int y, int count) {
  if (f[x][y]) return;
  f[x][y] = true;
  if (n[x][y] > count) n[x][y] = count;
  int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
  for (int i = 0; i < 4; i++) {
    int nx = x + dx[i], ny = y + dy[i];
    if (!(nx < h && ny < w)) continue;
    if (field[nx][ny] == '.') {
      bfs(nx, ny, count + 1);
    }
  }
  f[x][y] = false;
}
int main() {
  cin >> h >> w;
  int result = 0;
  for (int i = 0; i < h; i++) cin >> field[i];
  for (int i = 0; i < h; i++)
    for (int j = 0; j < w; j++) {
      for (int ii = 0; ii < 25; ii++)
        for (int jj = 0; jj < 25; jj++) {
          n[ii][jj] = 100000;
          f[ii][jj] = false;
        }
      if (field[i][j] == '.')
        bfs(i, j, 0);
      else
        continue;
      for (int ii = 0; ii < h; ii++)
        for (int jj = 0; jj < w; jj++) {
          if (field[ii][jj] == '#') continue;
          result = max(result, n[ii][jj]);
        }
    }
  cout << result << endl;
}
