#include <bits/stdc++.h>
using namespace std;

int h, w;
string field[25];
int c[25][25];

int bfs(int x, int y, int count) {
  c[x][y] = count;

  int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
  int result = -1;
  for(int i=0; i < 4; i++) {
    int nx = x+dx[i], ny = y+dy[i];
    if(0 <= nx && nx < h && 0 <= ny && ny < w && field[nx][ny] == '.') {
      if(c[nx][ny] <= count+1) continue;
      result = max(bfs(nx, ny, count+1), result);
    }
  }
  return result;
}

int main() {
  cin >> h >> w;
  for(int i=0; i < h; i++) cin >> field[i];

  int result = -1;
  for(int i=0; i < h; i++) for(int j=0; j < w; j++) {
    if(field[i][j] == '#') continue;
    for(int a=0; a < 25; a++) for(int b=0; b < 25; b++){
      c[a][b] = 100000;
    }

    bfs(i, j, 0);

    for(int a=0; a < h; a++) for(int b=0; b < w; b++) {
      if(field[a][b] == '#') continue;
      result = max(result, c[a][b]);
    }
  }
  cout << result << endl;
}
