#include <bits/stdc++.h>
using namespace std;
int main() {
  int h, w;
  cin >> h >> w;
  vector<vector<int>> map(h + 2, vector<int>(w + 2, -2));
  for (int i = 0, i_len = (h); i < i_len; ++i)
    for (int j = 0, j_len = (w); j < j_len; ++j) {
      char c;
      cin >> c;
      if (c == '.') map[i + 1][j + 1] = -1;
    }
  int ans = 0;
  vector<vector<int>> backup = map;
  for (int ri = 1, ri_len = (h + 1); ri < ri_len; ++ri)
    for (int rj = 1, rj_len = (w + 1); rj < rj_len; ++rj) {
      queue<pair<int, int>> q;
      q.push(make_pair(ri, rj));
      map = backup;
      map[ri][rj] = 0;
      vector<int> di = {-1, 0, 0, 1};
      vector<int> dj = {0, -1, 1, 0};
      int m = 0;
      while (!q.empty()) {
        int i = q.front().first;
        int j = q.front().second;
        q.pop();
        for (int k = 0, k_len = (4); k < k_len; ++k) {
          int ni = i + di[k];
          int nj = j + dj[k];
          if (map[ni][nj] == -1) {
            q.push(make_pair(ni, nj));
            map[ni][nj] = map[i][j] + 1;
            m = max(m, map[ni][nj]);
          }
        }
      }
      ans = max(ans, m);
    }
  cout << ans << endl;
}
