#include <bits/stdc++.h>
using namespace std;
vector<int> dxs = {-1, 1, 0, 0}, dys = {0, 0, -1, 1};
int main() {
  int h, w;
  cin >> h >> w;
  vector<string> s(h);
  for (int i = 0; i < h; i++) {
    cin >> s.at(i);
  }
  int res = 0;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (s.at(i).at(j) == '#') {
        continue;
      }
      int mx = 0;
      vector<vector<bool>> v(h, vector<bool>(w, true));
      queue<pair<pair<int, int>, int>> q;
      q.push({{i, j}, 0});
      while (!q.empty()) {
        int pi = q.front().first.first, pj = q.front().first.second;
        int l = q.front().second;
        q.pop();
        v.at(pi).at(pj) = false;
        mx = max(mx, l);
        for (int k = 0; k < 4; k++) {
          int dx = dxs.at(k), dy = dys.at(k);
          if (0 <= pi + dy && pi + dy < h && 0 <= pj + dx && pj + dx < w) {
            if (s.at(pi + dy).at(pj + dx) == '.' && v.at(pi + dy).at(pj + dx)) {
              q.push({{pi + dy, pj + dx}, l + 1});
            }
          }
        }
      }
      res = max(res, mx);
    }
  }
  cout << res << endl;
}
