#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
const long long MOD = 1000000007;
const int MAX = 510000;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
int main() {
  int H, W;
  cin >> H >> W;
  vector<string> field(H);
  for (int i = 0; i < H; i++) cin >> field[i];
  vector<int> res;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      vector<vector<int>> dist(H, vector<int>(W, -1));
      queue<pair<int, int>> que;
      dist[i][j] = 0;
      que.push(make_pair(i, j));
      int num = 0;
      while (!que.empty()) {
        pair<int, int> p = que.front();
        que.pop();
        num = max(num, dist[p.first][p.second]);
        for (int dir = 0; dir < 4; dir++) {
          int nh = p.first + dx[dir], nw = p.second + dy[dir];
          if (nh < 0 || nh >= H || nw < 0 || nw >= W) continue;
          if (field[nh][nw] == '#') continue;
          if (dist[nh][nw] != -1) continue;
          dist[nh][nw] = dist[p.first][p.second] + 1;
          que.push(make_pair(nh, nw));
        }
      }
      res.push_back(num);
    }
  }
  sort(res.begin(), res.end());
  reverse(res.begin(), res.end());
  cout << res[0] << endl;
  return 0;
}
