#include <bits/stdc++.h>
using namespace std;
const int INF = 1001001001;
int main() {
  int H, W;
  cin >> H >> W;
  vector<string> S(H);
  for (int i = 0; i < H; i++) {
    cin >> S[i];
  }
  queue<pair<int, int>> q;
  vector<int> dx = {0, 0, 1, -1};
  vector<int> dy = {1, -1, 0, 0};
  int ans = 0;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      q.push(make_pair(i, j));
      int MAXC = 0;
      vector<vector<int>> cost(H, vector<int>(W, -1));
      cost[i][j] = 0;
      while (!q.empty()) {
        auto p = q.front();
        q.pop();
        int y, x;
        tie(y, x) = p;
        for (int d = 0; d < 4; d++) {
          if (y + dy[d] >= H || x + dx[d] >= W || y + dy[d] < 0 ||
              x + dx[d] < 0) {
            continue;
          }
          if (cost[y + dy[d]][x + dx[d]] != -1) {
            continue;
          }
          if (S[y + dy[d]][x + dx[d]] == '#') {
            continue;
          }
          cost[y + dy[d]][x + dx[d]] = cost[y][x] + 1;
          q.push(make_pair(y + dy[d], x + dx[d]));
        }
        ans = max(ans, cost[y][x]);
      }
    }
  }
  cout << ans << endl;
  return 0;
}
