#include <bits/stdc++.h>
using namespace std;
struct Path {
  int x, y, n;
};
int h, w;
deque<Path> q;
vector<string> s;
vector<vector<int>> used;
vector<pair<int, int>> moves = {
    {-1, 0},
    {0, -1},
    {0, 1},
    {1, 0},
};
int bfs(int start_x, int start_y) {
  q.clear();
  for (auto &row : used) {
    fill(row.begin(), row.end(), 0);
  }
  q.push_back({start_x, start_y, 0});
  int res = 0;
  while (!q.empty()) {
    auto p = q.front();
    q.pop_front();
    res = max(res, p.n);
    used[p.x][p.y] = true;
    for (auto move : moves) {
      int x = p.x + move.first;
      int y = p.y + move.second;
      if (x >= 0 && x < h && y >= 0 && y < w && s[x][y] != '#' && !used[x][y]) {
        q.push_back({x, y, p.n + 1});
      }
    }
  }
  return res;
}
int main() {
  cin >> h >> w;
  s.resize(h);
  used.resize(h, vector<int>(w));
  for (int i = 0; i < h; ++i) {
    cin >> s[i];
  }
  int res = 0;
  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j) {
      if (s[i][j] != '#') {
        res = max(res, bfs(i, j));
      }
    }
  }
  cout << res << "\n";
  return 0;
}
