#include <bits/stdc++.h>
using namespace std;
int main() {
  int h, w;
  cin >> h >> w;
  vector<vector<char>> s(h, vector<char>(w));
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      cin >> s.at(i).at(j);
    }
  }
  int ans = 0;
  vector<int> dx = {1, -1, 0, 0}, dy = {0, 0, 1, -1};
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (s.at(i).at(j) == '#') break;
      vector<vector<int>> dir(h, vector<int>(w, -1));
      dir.at(i).at(j) = 0;
      queue<pair<int, int>> q;
      q.push(make_pair(i, j));
      while (q.size() > 0) {
        pair<int, int> p = q.front();
        q.pop();
        int x = p.first, y = p.second;
        for (int k = 0; k < 4; k++) {
          int nx = x + dx.at(k), ny = y + dy.at(k);
          if (0 <= nx && nx < h && 0 <= ny && ny < w &&
              s.at(nx).at(ny) == '.' && dir.at(nx).at(ny) == -1) {
            dir.at(nx).at(ny) = dir.at(x).at(y) + 1;
            q.push(make_pair(nx, ny));
          }
        }
      }
      int ma = 0;
      for (int k = 0; k < h; k++) {
        for (int l = 0; l < w; l++) {
          ma = max(ma, dir.at(k).at(l));
        }
      }
      ans = max(ans, ma);
    }
  }
  cout << ans << endl;
}
