#include <bits/stdc++.h>
using namespace std;
int main() {
  int h, w, ans = 0;
  cin >> h >> w;
  vector<string> s;
  s.push_back(string(w + 2, '0'));
  for (int i = 0; i < h; ++i) {
    string _s;
    cin >> _s;
    _s = '0' + _s + '0';
    s.push_back(_s);
  }
  s.push_back(string(w + 2, '0'));
  for (int sh = 1; sh <= h; ++sh) {
    for (int sw = 1; sw <= w; ++sw) {
      if (s[sh][sw] == '.') {
        queue<pair<pair<int, int>, int>> q;
        q.push(make_pair(make_pair(sh, sw), 0));
        vector<vector<bool>> check(h + 2, vector<bool>(w + 2, false));
        while (q.size()) {
          auto ijc = q.front();
          q.pop();
          int i = ijc.first.first, j = ijc.first.second, c = ijc.second;
          check[i][j] = true;
          if (s[i - 1][j] == '.' && check[i - 1][j] == false) {
            q.push(make_pair(make_pair(i - 1, j), c + 1));
          }
          if (s[i + 1][j] == '.' && check[i + 1][j] == false) {
            q.push(make_pair(make_pair(i + 1, j), c + 1));
          }
          if (s[i][j - 1] == '.' && check[i][j - 1] == false) {
            q.push(make_pair(make_pair(i, j - 1), c + 1));
          }
          if (s[i][j + 1] == '.' && check[i][j + 1] == false) {
            q.push(make_pair(make_pair(i, j + 1), c + 1));
          }
          ans = max(ans, c);
        }
      }
    }
  }
  cout << ans << '\n';
  return 0;
}
