#include <bits/stdc++.h>
using namespace std;
const int di[] = {-1, 0, 1, 0};
const int dj[] = {0, -1, 0, 1};
int main() {
  int H, W;
  cin >> H >> W;
  vector<string> s(H);
  for (int i = 0; i < (int)H; ++i) cin >> s.at(i);
  int ans = 0;
  for (int si = 0; si < (int)H; ++si)
    for (int sj = 0; sj < (int)W; ++sj) {
      if (s.at(si).at(sj) == '#') continue;
      vector<vector<int>> cost(H, vector<int>(W, 100100100));
      queue<pair<int, int>> q;
      auto update = [&](int i, int j, int c) {
        if (cost[i][j] != 100100100) return;
        cost[i][j] = c;
        q.push(pair<int, int>(i, j));
      };
      update(si, sj, 0);
      while (!q.empty()) {
        int i = q.front().first;
        int j = q.front().second;
        q.pop();
        for (int k = 0; k < (int)4; ++k) {
          if (i + di[k] < 0 || H <= i + di[k] || j + dj[k] < 0 ||
              W <= j + dj[k])
            continue;
          if (s[i][j] == '#') continue;
          update(i + di[k], j + dj[k], cost[i][j] + 1);
        }
      }
      for (int ci = 0; ci < (int)H; ++ci)
        for (int cj = 0; cj < (int)W; ++cj) {
          if (cost[ci][cj] == 100100100) continue;
          ans = max(ans, cost[ci][cj]);
        }
    }
  cout << ans << endl;
  return 0;
}
