#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll Mod = 1000000007;
int H, W;
char field[24][24];
int dis[24][24];
bool have[24][24];
int dx[4] = {1, -1, 0, 0};
int dy[4] = {0, 0, 1, -1};
int DFS(int x, int y) {
  int res = -1;
  queue<pair<int, int>> Q;
  for (int i = 0; i < 24; i++) {
    for (int j = 0; j < 24; j++) {
      dis[i][j] = -1;
      have[i][j] = false;
    }
  }
  dis[x][y] = 0;
  Q.push(make_pair(x, y));
  while (!Q.empty()) {
    pair<int, int> T = Q.front();
    int ax = T.first;
    int ay = T.second;
    Q.pop();
    for (int i = 0; i < 4; i++) {
      int fx = dx[i] + ax;
      int fy = dy[i] + ay;
      if (0 <= fx && fx < H && 0 <= fy && fy < W) {
        if (!have[fx][fy] && field[fx][fy] == '.') {
          have[fx][fy] = true;
          dis[fx][fy] = dis[ax][ay] + 1;
          res = max(res, dis[fx][fy]);
          Q.push(make_pair(fx, fy));
        }
      }
    }
  }
  return res;
}
int main() {
  cin >> H >> W;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      cin >> field[i][j];
    }
  }
  int ans = -1;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      if (field[i][j] == '.') {
        ans = max(ans, DFS(i, j));
      }
    }
  }
  cout << ans << endl;
  return 0;
}
