#include <bits/stdc++.h>
using namespace std;
using LP = pair<long long, long long>;
using P = pair<int, int>;
const int inf = 500;
int h, w;
char g[21][21];
int di[4] = {-1, 0, 1, 0};
int dj[4] = {0, 1, 0, -1};
int bfs(int si, int sj) {
  if (g[si][sj] == '#') return inf;
  vector<vector<int>> dist(h, vector<int>(w, inf));
  dist[si][sj] = 0;
  deque<P> q;
  q.emplace_back(si, sj);
  while (!q.empty()) {
    P now = q.front();
    q.pop_front();
    int i = now.first;
    int j = now.second;
    for (int k = 0; k < 4; k++) {
      int ni = i + di[k];
      int nj = j + dj[k];
      if (ni < 0 or ni >= h or nj < 0 or nj >= w) continue;
      if (g[ni][nj] == '#') continue;
      if (dist[ni][nj] > dist[i][j] + 1) {
        dist[ni][nj] = dist[i][j] + 1;
        q.emplace_back(ni, nj);
      }
    }
  }
  int m = 0;
  for (int i = 0; i < h; i++)
    for (int j = 0; j < w; j++) {
      if (dist[i][j] == inf) continue;
      m = max(m, dist[i][j]);
    }
  return m;
}
int main() {
  cin >> h >> w;
  vector<vector<int>> ans(h, vector<int>(w, inf));
  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++) {
      int m = bfs(i, j);
      ans[i][j] = m;
    }
  int m = 0;
  for (int i = 0; i < h; i++)
    for (int j = 0; j < h; j++) {
      if (ans[i][j] == inf) continue;
      m = max(m, ans[i][j]);
    }
  cout << m << endl;
}
