#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
const long long MAX = 2147483647;
pair<int, int> d[4] = {make_pair(1, 0), make_pair(0, 1), make_pair(-1, 0),
                       make_pair(0, -1)};
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int h, w;
  cin >> h >> w;
  vector<string> g(h + 2, string(w + 2, '#'));
  for (int i = 1; i <= h; i++) {
    cin >> g[i];
    g[i] = '#' + g[i] + '#';
  }
  int ans = 0;
  for (int i = 1; i <= h; i++) {
    for (int j = 1; j <= w; j++) {
      if (g[i][j] == '#') continue;
      vector<vector<bool>> visit(h + 2, vector<bool>(w + 2));
      queue<pair<pair<int, int>, int>> q;
      q.push(make_pair(make_pair(i, j), 0));
      while (!q.empty()) {
        ans = max(ans, q.front().second);
        for (auto& k : d) {
          pair<int, int> nw = make_pair(q.front().first.first + k.first,
                                        q.front().first.second + k.second);
          if (g[nw.first][nw.second] == '#' || visit[nw.first][nw.second])
            continue;
          visit[nw.first][nw.second] = true;
          q.push(make_pair(nw, q.front().second + 1));
        }
        q.pop();
      }
    }
  }
  cout << ans << "\n";
  return 0;
}
