#include <bits/stdc++.h>
using namespace std;
const char WALL = '#';
int main() {
  vector<pair<int, int>> moves = {
      {0, 1},
      {0, -1},
      {1, 0},
      {-1, 0},
  };
  int h, w;
  cin >> h >> w;
  vector<string> s(h + 2);
  s[0] = string(w + 2, WALL);
  s[h + 1] = string(w + 2, WALL);
  for (int i = 1; i <= h; ++i) {
    string ss;
    cin >> ss;
    s[i] = WALL + ss + WALL;
  }
  vector<tuple<int, int, int>> q((h + 2) * (w + 2));
  vector<vector<int>> used(h + 2, vector<int>(w + 2));
  int answer = 0;
  for (int sx = 1; sx <= h; ++sx) {
    for (int sy = 1; sy <= w; ++sy) {
      if (s[sx][sy] == WALL) {
        continue;
      }
      for (auto &row : used) {
        fill(row.begin(), row.end(), 0);
      }
      q.clear();
      q.emplace_back(sx, sy, 0);
      used[sx][sy] = true;
      for (int i = 0; i < (int)q.size(); ++i) {
        auto [x, y, d] = q[i];
        for (auto [dx, dy] : moves) {
          int xx = x + dx;
          int yy = y + dy;
          if (s[xx][yy] != WALL && !used[xx][yy]) {
            used[xx][yy] = true;
            q.emplace_back(xx, yy, d + 1);
          }
        }
      }
      answer = max(answer, get<2>(q.back()));
    }
  }
  cout << answer << "\n";
  return 0;
}
