#include <bits/stdc++.h>
using namespace std;
const int N = 21;
int h, w, res;
char G[N][N];
bool visited[N][N];
void bfs(int i, int j) {
  memset(visited, 0, sizeof visited);
  vector<pair<int, int> > dxy = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};
  vector<pair<int, int> > cur = {{i, j}};
  vector<pair<int, int> > next;
  int dist = 0;
  while (true) {
    for (auto p1 : cur) {
      int x = p1.first, y = p1.second;
      for (auto p2 : dxy) {
        int dx = p2.first, dy = p2.second;
        int nx = x + dx, ny = y + dy;
        if (nx < 0 || ny < 0 || nx == h || ny == w || visited[nx][ny]) continue;
        if (G[nx][ny] == '.') {
          visited[nx][ny] = true;
          next.push_back({nx, ny});
        }
      }
    }
    if (next.empty()) break;
    dist++;
    swap(cur, next);
    next.clear();
  }
  res = max(res, dist);
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> h >> w;
  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j) {
      cin >> G[i][j];
    }
  }
  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j) {
      bfs(i, j);
    }
  }
  cout << res << endl;
  return 0;
}
