#include <bits/stdc++.h>
using namespace std;
int H, W;
int bfs(vector<string> S, int sx, int sy) {
  int F[H][W];
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      F[i][j] = 0;
      if (S[i][j] == '.') {
        F[i][j] = -1;
      }
    }
  }
  bool flag = false;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      if (S[i][j] == '.') {
        flag = true;
        break;
      }
    }
    if (flag) break;
  }
  queue<pair<int, int>> que;
  que.push(make_pair(sx, sy));
  int x, y, gx, gy;
  vector<int> vec1 = {1, 0, -1, 0};
  vector<int> vec2 = {0, 1, 0, -1};
  bool flag2;
  while (que.size() > 0) {
    x = que.front().first;
    y = que.front().second;
    que.pop();
    int res = 0;
    res = max(res, F[x][y]);
    for (int i = 0; i < 4; i++) {
      if (0 <= x + vec1[i] && x + vec1[i] < H && 0 <= y + vec2[i] &&
          y + vec2[i] < W) {
        if (S[x + vec1[i]][y + vec2[i]] == '.' &&
            F[x + vec1[i]][y + vec2[i]] == -1) {
          gx = x + vec1[i];
          gy = y + vec2[i];
          F[x + vec1[i]][y + vec2[i]] = res + 1;
          que.push(make_pair(x + vec1[i], y + vec2[i]));
        }
      }
    }
    flag2 = true;
    for (int i = 0; i < H; i++) {
      for (int j = 0; j < W; j++) {
        if (F[i][j] == -1) flag2 = false;
      }
    }
    if (flag2) break;
  }
  return F[gx][gy];
}
int main() {
  cin >> H >> W;
  vector<string> S(H);
  for (int i = 0; i < H; i++) {
    cin >> S[i];
  }
  int res = 0;
  for (int x = 0; x < H; ++x) {
    for (int y = 0; y < W; ++y) {
      if (S[x][y] == '#') continue;
      res = max(res, bfs(S, x, y));
    }
  }
  cout << res << endl;
}
