#include <bits/stdc++.h>
using namespace std;
int main() {
  int H, W, i, j, ans = 0;
  scanf("%d%d", &H, &W);
  vector<string> S(H);
  for (i = 0; i < H; i++) {
    cin >> S[i];
  }
  int dx[4] = {0, 1, 0, -1};
  int dy[4] = {1, 0, -1, 0};
  for (i = 0; i < H; i++) {
    for (j = 0; j < W; j++) {
      if (S[i][j] == '#') {
        continue;
      }
      vector<vector<int>> dis(H, vector<int>(W, (int)(1e9)));
      queue<pair<pair<int, int>, int>> q;
      q.push(make_pair(make_pair(i, j), 0));
      while (q.size() > 0) {
        int x = q.front().first.first;
        int y = q.front().first.second;
        int v = q.front().second;
        q.pop();
        if (x < 0 || H <= x || y < 0 || W <= y || S[x][y] == '#' ||
            dis[x][y] < v) {
          continue;
        }
        dis[x][y] = v;
        ans = max(ans, v);
        for (int d = 0; d < 4; d++) {
          q.push(make_pair(make_pair(x + dx[d], y + dy[d]), v + 1));
        }
      }
    }
  }
  printf("%d\n", ans);
  return 0;
}
