#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int H, W;
bool inBoard(int y, int x) {
  if (y >= 0 && y < H && x >= 0 && x < W) {
    return true;
  }
  return false;
}
int main() {
  cin >> H >> W;
  vector<string> S;
  S.resize(H);
  for (int i = 0; i < H; i++) {
    cin >> S[i];
  }
  int dx[4] = {1, 0, -1, 0};
  int dy[4] = {0, 1, 0, -1};
  ll ans = 0;
  for (int sy = 0; sy < H; sy++) {
    for (int sx = 0; sx < W; sx++) {
      ll d[H][W];
      memset(d, -1, sizeof(d));
      d[sy][sx] = 0;
      queue<pair<int, int>> q;
      q.emplace(sy, sx);
      while (!q.empty()) {
        int y = q.front().first;
        int x = q.front().second;
        ans = max(ans, d[y][x]);
        q.pop();
        for (int i = 0; i < 4; i++) {
          int ny = y + dy[i];
          int nx = x + dx[i];
          if (inBoard(ny, nx) && S[ny][nx] == '.' && d[ny][nx] == -1) {
            d[ny][nx] = d[y][x] + 1;
            q.emplace(ny, nx);
          }
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}
