#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 7;
char grid[25][25];
int dist[25][25];
int dx[4] = {0, 0, -1, 1}, dy[4] = {1, -1, 0, 0};
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int h, w;
  cin >> h >> w;
  queue<pair<int, int> > q, source;
  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j) {
      cin >> grid[j][i];
      dist[j][i] = INF;
      if (grid[j][i] == '.') {
        source.emplace(j, i);
      }
    }
  }
  int ans = 0;
  while (source.size()) {
    for (int i = 0; i < h; ++i) {
      for (int j = 0; j < w; ++j) dist[j][i] = INF;
    }
    dist[source.front().first][source.front().second] = 0;
    q.emplace(source.front().first, source.front().second);
    source.pop();
    while (q.size()) {
      int cx = q.front().first;
      int cy = q.front().second;
      q.pop();
      for (int i = 0; i < 4; ++i) {
        int nx = cx + dx[i];
        int ny = cy + dy[i];
        if (nx < 0 || nx >= w || ny < 0 || ny >= h) continue;
        if (grid[nx][ny] == '#') continue;
        if (dist[nx][ny] < dist[cx][cy] + 1) continue;
        dist[nx][ny] = dist[cx][cy] + 1;
        q.emplace(nx, ny);
      }
    }
    for (int i = 0; i < h; ++i) {
      for (int j = 0; j < w; ++j) {
        if (dist[j][i] != INF) ans = max(ans, dist[j][i]);
      }
    }
  }
  cout << ans;
  return 0;
}
