#include <bits/stdc++.h>
using namespace std;
int dir[4][2] = {{0, 1}, {1, 0}, {0, -1}, {-1, 0}};
int dist(int s, int t, int h, int w, vector<string> &map) {
  queue<pair<int, pair<int, int>>> q;
  q.push(make_pair(0, make_pair(s, t)));
  int maxm = 0;
  vector<vector<int>> dist(h, vector<int>(w, INT_MAX));
  while (!q.empty()) {
    pair<int, pair<int, int>> p = q.front();
    q.pop();
    int nextm = p.first + 1;
    for (int i = 0; i < 4; ++i) {
      int u = p.second.first + dir[i][0], v = p.second.second + dir[i][1];
      if (u < 0 || u >= h || v < 0 || v >= w) continue;
      if (map[u][v] == '.' && nextm < dist[u][v]) {
        dist[u][v] = nextm;
        q.push(make_pair(nextm, make_pair(u, v)));
        maxm = max(maxm, nextm);
      }
    }
  }
  return maxm;
}
int main() {
  int h, w;
  cin >> h >> w;
  vector<string> map(h);
  for (int i = 0; i < h; ++i) cin >> map[i];
  int maxd = 0;
  for (int i = 0; i < h; ++i)
    for (int j = 0; j < w; ++j)
      if (map[i][j] == '.') maxd = max(maxd, dist(i, j, h, w, map));
  cout << maxd << endl;
}
