#include <bits/stdc++.h>
using namespace std;
int MOD = 1000000007;
int h, w;
vector<string> maze(30);
vector<vector<int>> has(30, vector<int>(30));
vector<vector<int>> dist(30, vector<int>(30));
int movex[] = {-1, 1, 0, 0};
int movey[] = {0, 0, -1, 1};
int dfs(int x, int y, int len) {
  has[x][y] = 1;
  dist[x][y] = min(dist[x][y], len);
  for (int i = 0; i < 4; i++) {
    int nx = x + movex[i];
    int ny = y + movey[i];
    if (nx >= 0 && nx < h && ny >= 0 && ny < w) {
      if (maze[nx][ny] == '.' && has[nx][ny] == 0) {
        dfs(nx, ny, len + 1);
      }
    }
  }
  has[x][y] = 0;
  return 0;
}
int main() {
  cin >> h >> w;
  for (int i = 0; i < h; i++) {
    cin >> maze[i];
  }
  int maxv = 0;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (maze[i][j] == '.') {
        for (int k = 0; k < h; k++) {
          for (int l = 0; l < w; l++) {
            has[k][l] = 0;
            dist[k][l] = 10000;
          }
        }
        dist[i][j] = 0;
        dfs(i, j, 0);
        for (int k = 0; k < h; k++) {
          for (int l = 0; l < w; l++)
            if (dist[k][l] != 10000) {
              maxv = max(maxv, dist[k][l]);
            }
        }
      }
    }
  }
  cout << maxv << endl;
  return 0;
}
