#include <bits/stdc++.h>
using namespace std;
long long n, m;
char ch;
long long blk[505][505] = {0};
long long vis[505][505] = {0};
long long dx[4] = {0, 0, 1, -1};
long long dy[4] = {1, -1, 0, 0};
struct node {
  long long x, y, stp;
} h, t;
queue<node> q;
long long bfs(long long x, long long y) {
  long long ret = 0;
  for (long long i = 1; i <= n; i++)
    for (long long j = 1; j <= m; j++) vis[i][j] = 0;
  while (!q.empty()) q.pop();
  h.x = x;
  h.y = y;
  h.stp = 0;
  q.push(h);
  vis[x][y] = 1;
  while (!q.empty()) {
    h = q.front();
    q.pop();
    ret = max(ret, h.stp);
    for (long long i = 0; i < 4; i++) {
      long long tx, ty;
      tx = h.x + dx[i];
      ty = h.y + dy[i];
      if (blk[tx][ty] || vis[tx][ty] || tx < 1 || ty < 1 || tx > n || ty > m)
        continue;
      vis[tx][ty] = 1;
      t.x = tx;
      t.y = ty;
      t.stp = h.stp + 1;
      q.push(t);
    }
  }
  return ret;
}
int main() {
  cin >> n >> m;
  for (long long i = 1; i <= n; i++) {
    for (long long j = 1; j <= m; j++) {
      cin >> ch;
      if (ch == '#') blk[i][j] = 1;
    }
  }
  long long ans = 0, mx = 0;
  for (long long i = 1; i <= n; i++) {
    for (long long j = 1; j <= m; j++) {
      if (blk[i][j]) continue;
      mx = bfs(i, j);
      cout << mx << endl;
      ans = max(ans, mx);
    }
  }
  cout << ans << endl;
  return 0;
}
