#include <bits/stdc++.h>
using namespace std;
void dfs(vector<string> &vec, vector<vector<long long int> > &visited,
         long long int a, long long int b, long long int count, long long int h,
         long long int w) {
  if (a >= h || b >= w || a < 0 || b < 0) {
    return;
  }
  if (vec[a][b] == '#') return;
  if (visited[a][b] > 0) return;
  visited[a][b] = count;
  dfs(vec, visited, a + 1, b, count + 1, h, w);
  dfs(vec, visited, a - 1, b, count + 1, h, w);
  dfs(vec, visited, a, b + 1, count + 1, h, w);
  dfs(vec, visited, a, b - 1, count + 1, h, w);
}
int main() {
  long long int h, w;
  cin >> h >> w;
  vector<string> vec;
  for (long long int i = 1; i <= h; i++) {
    string s;
    cin >> s;
    vec.push_back(s);
  }
  long long int ans = 0;
  for (long long int i = 0; i < h; i++) {
    for (long long int j = 0; j < w; j++) {
      if (vec[i][j] == '.') {
        vector<vector<long long int> > visited(h, vector<long long int>(w, 0));
        long long int count = 1;
        dfs(vec, visited, i, j, count, h, w);
        for (long long int k = 0; k < h; k++) {
          for (long long int l = 0; l < w; l++) {
            count = max(count, visited[k][l] - 1);
          }
        }
        ans = max(ans, count);
      }
    }
  }
  cout << ans << endl;
}
