#include <bits/stdc++.h>
using namespace std;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
int main() {
  int h, w;
  cin >> h >> w;
  char s[h][w];
  for (int i = 0; i < h; i++)
    for (int j = 0; j < w; j++) cin >> s[i][j];
  int ans = 0;
  vector<pair<int, int> > ind;
  for (int i = 0; i < h; i++)
    for (int j = 0; j < w; j++) ind.push_back(pair<int, int>(i, j));
  for (int i = 0; i < ind.size(); i++) {
    for (int j = 0; j < ind.size(); j++) {
      if (s[ind[i].first][ind[i].first] == '#' ||
          s[ind[j].second][ind[j].second] == '#')
        continue;
      int d[h][w];
      for (int i = 0; i < h; i++)
        for (int j = 0; j < w; j++) d[i][j] = 0;
      queue<pair<int, int> > q;
      q.push(pair<int, int>(ind[i].first, ind[i].second));
      bool flag = 0;
      while (!q.empty()) {
        pair<int, int> u = q.front();
        q.pop();
        if (u.first == ind[j].first && u.second == ind[j].second) {
          flag = 1;
          break;
        }
        for (int k = 0; k < 4; k++) {
          int x = u.first + dx[k], y = u.second + dy[k];
          if (!((0 <= x && x < h) && (0 <= y && y < w))) continue;
          if (s[x][y] == '#' || d[x][y] > 0) continue;
          d[x][y] = d[u.first][u.second] + 1;
          q.push(pair<int, int>(x, y));
        }
      }
      if (flag == 1) ans = max(ans, d[ind[j].first][ind[j].second]);
    }
  }
  cout << ans << endl;
  return 0;
}
