#include <bits/stdc++.h>
using namespace std;
template <class T>
void sort(vector<T> &v) {
  sort(v.begin(), v.end());
}
int h, w;
int ptoi(int i, int j) { return w * i + j; }
int main() {
  cin >> h >> w;
  vector<vector<char>> s(h, vector<char>(w));
  for (int i = 0; i < h * w; i++) cin >> s[i / w][i % w];
  vector<vector<int>> cost(h * w, vector<int>(h * w, 100000000));
  for (int i = 0; i < h * w; i++) cost[i][i] = 0;
  for (int i = 0; i < h; i++)
    for (int j = 0; j < w; j++) {
      if (s[i][j] == '#') continue;
      if (i - 1 >= 0 && s[i - 1][j] == '.')
        cost[ptoi(i, j)][ptoi(i - 1, j)] = 1;
      if (j - 1 >= 0 && s[i][j - 1] == '.')
        cost[ptoi(i, j)][ptoi(i, j - 1)] = 1;
      if (i + 1 < h && s[i + 1][j] == '.') cost[ptoi(i, j)][ptoi(i + 1, j)] = 1;
      if (j + 1 < w && s[i][j + 1] == '.') cost[ptoi(i, j)][ptoi(i, j + 1)] = 1;
    }
  for (int i = 0; i < h * w; i++)
    for (int j = 0; j < h * w; j++)
      cost[i][j] = cost[j][i] = min(cost[i][j], cost[j][i]);
  set<int> road;
  for (int i = 0; i < h; i++)
    for (int j = 0; j < w; j++)
      if (s[i][j] == '.') road.insert(ptoi(i, j));
  for (int k = 0; k < h * w; k++)
    for (int i = 0; i < h * w; i++)
      for (int j = 0; j < h * w; j++) {
        if (road.count(k) == 0) continue;
        if (road.count(j) == 0) continue;
        if (road.count(i) == 0) continue;
        cost[i][j] = min(cost[i][j], cost[i][k] + cost[k][j]);
      }
  int ans = 0;
  for (auto i : road)
    for (auto j : road) ans = max(ans, cost[i][j]);
  cout << ans << endl;
  return 0;
}
