#include <bits/stdc++.h>
using namespace std;
int ans = 0;
int H, W;
void bfs(vector<string> &S, int sy, int sx, int ey, int ex) {
  vector<int> vx = {0, 1, 0, -1};
  vector<int> vy = {1, 0, -1, 0};
  queue<int> quex;
  queue<int> quey;
  quex.push(sx);
  quey.push(sy);
  vector<vector<int>> dis(H, vector<int>(W, 1e9));
  dis.at(sy).at(sx) = 0;
  while (!quex.empty() && !quey.empty()) {
    int x = quex.front();
    int y = quey.front();
    quex.pop();
    quey.pop();
    for (int i = 0; i < 4; i++) {
      int next_x = x + vx.at(i);
      int next_y = y + vy.at(i);
      if (next_x < 0 || next_x >= W || next_y < 0 || next_y >= H) continue;
      if (S.at(next_y).at(next_x) == '#') continue;
      if (dis.at(next_y).at(next_x) != 1e9) continue;
      quex.push(next_x);
      quey.push(next_y);
      dis.at(next_y).at(next_x) = dis.at(y).at(x) + 1;
    }
  }
  if (dis.at(ey).at(ex) != 1e9) ans = max(ans, dis.at(ey).at(ex));
}
int main() {
  cin >> H >> W;
  vector<string> S(H);
  for (int i = 0; i < H; i++) cin >> S.at(i);
  for (int st_i = 0; st_i < H; st_i++) {
    for (int st_j = 0; st_j < W; st_j++) {
      for (int en_i = st_i; en_i < H; en_i++) {
        for (int en_j = st_j; en_j < W; en_j++) {
          if (S.at(st_i).at(st_j) == '#') continue;
          if (S.at(en_i).at(en_j) == '#') continue;
          bfs(S, st_i, st_j, en_i, en_j);
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}
