#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
long long H, W;
vector<vector<long long> > MAP;
long long bfs(long long sx, long long sy) {
  if (MAP[sx][sy] == 1) return 0;
  struct query {
    long long x, y, d;
  };
  queue<query> q;
  long long V[4][2] = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}};
  vector<vector<long long> > res;
  res.resize(W, vector<long long>(H, -1));
  q.push({sx, sy, 0});
  long long ans = 0;
  while (q.size() > 0) {
    long long x = q.front().x;
    long long y = q.front().y;
    long long d = q.front().d;
    q.pop();
    for (long long v = 0; v < 4; v++) {
      long long nx = x + V[v][0];
      long long ny = y + V[v][1];
      if (nx < 0 || nx >= W || ny < 0 || ny >= H) continue;
      if (MAP[nx][ny] == 1) continue;
      if (res[nx][ny] != -1) continue;
      res[nx][ny] = d + 1;
      q.push({nx, ny, d + 1});
      ans = max(ans, d + 1);
    }
  }
  return ans;
}
int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  cin >> H >> W;
  MAP.resize(W, vector<long long>(H, 0));
  for (long long y = 0; y < H; y++) {
    string S;
    cin >> S;
    for (long long x = 0; x < W; x++) {
      if (S[x] == '#') MAP[x][y] = 1;
    }
  }
  long long ans = 0;
  for (long long sx = 0; sx < W; sx++) {
    for (long long sy = 0; sy < H; sy++) {
      ans = max(ans, bfs(sx, sy));
    }
  }
  cout << ans << "\n";
  return 0;
}
