#include <bits/stdc++.h>
using namespace std;
int H, W;
vector<vector<char>> S;
int ans;
void bfs(int h, int w) {
  vector<vector<int>> dist(H, vector<int>(W, -1));
  dist.at(h).at(w) = 0;
  vector<int> mh(4), mw(4);
  mh = {-1, 0, 1, 0};
  mw = {0, 1, 0, -1};
  queue<pair<int, int>> Q;
  Q.push({h, w});
  while (Q.size()) {
    int h = Q.front().first;
    int w = Q.front().second;
    Q.pop();
    ans = max(ans, dist.at(h).at(w));
    for (int i = 0; i < 4; i++) {
      int nh = h + mh.at(i);
      int nw = w + mw.at(i);
      if (nh < 0 || nh >= H || nw < 0 || nw >= W) continue;
      if (S.at(nh).at(nw) == '#') continue;
      if (dist.at(nh).at(nw) == -1) {
        dist.at(nh).at(nw) = dist.at(h).at(w) + 1;
        Q.push({nh, nw});
      }
    }
  }
}
int main() {
  cin >> H >> W;
  S.resize(H, vector<char>(W));
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      cin >> S.at(i).at(j);
    }
  }
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      bfs(i, j);
    }
  }
  cout << ans << "\n";
}
