#include <bits/stdc++.h>
const int INF = 1 << 29;
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
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);
    }
  }
  vector<int> dx = {-1, 0, 1, 0};
  vector<int> dy = {0, 1, 0, -1};
  int distance = 0;
  for (int sy = 0; sy < H; sy++) {
    for (int sx = 0; sx < W; sx++) {
      vector<vector<int>> D(H, vector<int>(W, INF));
      int sdis = 0;
      queue<pair<int, int>> q;
      q.push(make_pair(sx, sy));
      D.at(sy).at(sx) = 0;
      while (!q.empty()) {
        pair<int, int> p = q.front();
        q.pop();
        int x = p.first;
        int y = p.second;
        for (int i = 0; i < 4; i++) {
          if (x + dx.at(i) >= 0 && x + dx.at(i) < W && y + dy.at(i) >= 0 &&
              y + dy.at(i) < H) {
            int X = x + dx.at(i);
            int Y = y + dy.at(i);
            if (S.at(Y).at(X) == '.' && D.at(Y).at(X) == INF) {
              q.push(make_pair(X, Y));
              D.at(Y).at(X) = D.at(y).at(x) + 1;
              distance = max(distance, D.at(Y).at(X));
              sdis = max(sdis, D.at(Y).at(X));
            }
          }
        }
      }
    }
  }
  cout << distance << endl;
}
