#include <bits/stdc++.h>
using namespace std;
long long h, w, ans, cur;
char grid[50][50];
long long dist[25][25];
deque<pair<long long, long long> > starting;
queue<pair<long long, long long> > q;
bool visited[40][40];
long long dx[] = {0, 1, -1, 0};
long long dy[] = {1, 0, 0, -1};
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> h >> w;
  for (long long i = 0; i < h; i++) {
    for (long long j = 0; j < w; j++) {
      cin >> grid[i][j];
      if (grid[i][j] == '.') starting.push_back(make_pair(i, j));
    }
  }
  while (starting.size()) {
    pair<long long, long long> topp = starting.front();
    starting.pop_front();
    q.push(topp);
    ans = max(ans, cur);
    cur = 0;
    memset(visited, 0, sizeof(visited));
    visited[topp.first][topp.second] = 1;
    memset(dist, 0, sizeof(dist));
    while (!q.empty()) {
      pair<long long, long long> fron = q.front();
      q.pop();
      for (long long i = 0; i < 4; i++) {
        long long nx = fron.first + dx[i], ny = fron.second + dy[i];
        if (nx < 0 || ny < 0 || nx >= h || ny >= w || grid[nx][ny] == '#' ||
            visited[nx][ny])
          continue;
        dist[nx][ny] = dist[fron.first][fron.second] + 1;
        cur = max(cur, dist[nx][ny]);
        q.push(make_pair(nx, ny));
      }
    }
    cout << ans;
  }
}
