#include <bits/stdc++.h>
using namespace std;
char mat[20][20];
int ans[20][20], H, W;
vector<pair<int, int>> sol;
int dr[] = {-1, 1, 0, 0};
int dc[] = {0, 0, -1, 1};
int getMinDist(int row, int col) {
  if (row < 0 || col < 0 || row >= H || col >= W)
    return 100000;
  else
    return ans[row][col];
}
void floodfill(int row, int col) {
  if (row < 0 || col < 0 || row >= H || col >= W || mat[row][col] != '.')
    return;
  mat[row][col] = 'X';
  sol.push_back({row, col});
  for (int i = 0; i < 4; ++i)
    ans[row][col] =
        min(ans[row][col], 1 + getMinDist(row + dr[i], col + dc[i]));
  for (int i = 0; i < 4; ++i) floodfill(row + dr[i], col + dc[i]);
}
int main() {
  cin >> H >> W;
  for (int i = 0; i < H; ++i) {
    for (int j = 0; j < W; ++j) {
      cin >> mat[i][j];
      ans[i][j] = 100000;
    }
  }
  int m = 0;
  for (int i = 0; i < H; ++i) {
    for (int j = 0; j < W; ++j) {
      if (mat[i][j] == '.') {
        sol.clear();
        ans[i][j] = 0;
        floodfill(i, j);
        for (int i = 0; i < H; ++i) {
          for (int j = 0; j < W; ++j) {
            if (ans[i][j] > m && ans[i][j] < 5000) m = ans[i][j];
            ans[i][j] = 100000;
          }
        }
        for (auto e : sol) mat[e.first][e.second] = '.';
      }
    }
  }
  cout << m << endl;
  return 0;
}
