#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
const int INF = 1001001001;
int h, w;
vector<string> s;
vector<vector<int>> d;
int dh[4] = {1, 0, -1, 0}, dw[4] = {0, 1, 0, -1};
int bfs(int sh, int sw) {
  queue<pair<int, int>> que;
  for (int i = 0; i <= h - 1; ++i)
    for (int j = 0; j <= w - 1; ++j) d[i][j] = INF;
  que.push(pair<int, int>(sh, sw));
  d[sh][sw] = 0;
  while (!que.empty()) {
    pair<int, int> p = que.front();
    que.pop();
    for (int i = 0; i <= 3; ++i) {
      int nh = p.first + dh[i], nw = p.second + dw[i];
      if (0 <= nh && nh < h && 0 <= nw && nw < w && s[nh][nw] != '#' &&
          d[nh][nw] == INF) {
        que.push(pair<int, int>(nh, nw));
        d[nh][nw] = d[p.first][p.second] + 1;
      }
    }
  }
  return 0;
}
int main() {
  cin >> h >> w;
  s.resize(h);
  d.resize(h);
  for (int i = 0; i <= h - 1; ++i) {
    cin >> s[i];
    d[i].resize(w);
  }
  int max_d = 0, ans = 0;
  for (int i = 0; i <= h - 1; ++i)
    for (int j = 0; j <= w - 1; ++j) {
      bfs(i, j);
      max_d = 0;
      for (int i = 0; i <= h - 1; ++i)
        for (int j = 0; j <= w - 1; ++j)
          if (d[i][j] != INF) max_d = max(max_d, d[i][j]);
      ans = max(ans, max_d);
    }
  cout << ans << endl;
  return 0;
}
