#include <bits/stdc++.h>
using namespace std;
int H, W;
vector<vector<char>> c(501, vector<char>(501));
vector<int> s(2);
vector<int> v1 = {1, 0, -1, 0}, v2 = {0, 1, 0, -1};
int DFS(vector<int> s, int d, vector<vector<bool>> &b) {
  int a = 0;
  if (s.at(0) < 0 || s.at(0) >= H || s.at(1) < 0 || s.at(1) >= W ||
      c.at(s[0]).at(s[1]) == '#' || b[s[0]][s[1]] == true) {
    return d;
  }
  b[s[0]][s[1]] = true;
  for (int i = 0; i < 4; i++) {
    a = max(a, DFS({s.at(0) + v1.at(i), s.at(1) + v2.at(i)}, d + 1, b));
  }
  return a;
}
int main() {
  int ans = 0;
  cin >> H >> W;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      cin >> c.at(i).at(j);
    }
  }
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      vector<vector<bool>> b(H, vector<bool>(W, false));
      s.at(0) = i;
      s.at(1) = j;
      ans = max(ans, DFS(s, 0, b));
    }
  }
  cout << ans - 1 << endl;
}
