#include <bits/stdc++.h>
using namespace std;
const int INF = 1000000000;
void Main() {
  int h, w;
  cin >> h >> w;
  char map[h][w];
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      cin >> map[i][j];
    }
  }
  int d[h * w][h * w];
  for (int i = 0; i < h * w; i++) {
    for (int j = 0; j < h * w; j++) {
      int ah = i / w;
      int aw = i % w;
      int bh = j / w;
      int bw = j % w;
      if (map[ah][aw] == '#' || map[bh][bw] == '#')
        d[i][j] = INF;
      else if (i == j) {
        d[i][j] = 0;
      } else {
        if (abs(ah - bh) == 1 && aw == bw)
          d[i][j] = 1;
        else if (abs(aw - bw) == 1 && ah == bh)
          d[i][j] = 1;
        else
          d[i][j] = INF - 1;
      }
    }
  }
  for (int k = 0; k < h * w; k++) {
    for (int i = 0; i < h * w; i++) {
      for (int j = 0; j < h * w; j++) {
        int ah = i / w;
        int aw = i % w;
        int bh = j / w;
        int bw = j % w;
        if (map[ah][aw] == '#' || map[bh][bw] == '#')
          d[i][j] = INF;
        else
          d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
      }
    }
  }
  int ans = 0;
  for (int i = 0; i < h * w; i++) {
    for (int j = 0; j < h + w; j++) {
      if (d[i][j] != INF) ans = max(ans, d[i][j]);
    }
  }
  cout << ans << endl;
}
int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  Main();
  return 0;
}
