#include <bits/stdc++.h>
using namespace std;
char arr[32][32];
long long dis[32][32];
long long id[32][32];
signed main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  long long n, m, i, j, k;
  cin >> n >> m;
  k = 0;
  for (i = 1; i <= n; i++)
    for (j = 1; j <= m; j++) id[i][j] = k++;
  for (i = 1; i <= n; i++)
    for (j = 1; j <= m; j++) cin >> arr[i][j];
  for (i = 0; i < k; i++)
    for (j = 0; j < k; j++)
      if (i != j) dis[i][j] = dis[j][i] = 9999;
  for (i = 1; i <= n; i++) {
    for (j = 1; j <= m; j++) {
      if (i + 1 <= n)
        dis[id[i][j]][id[i + 1][j]] = dis[id[i + 1][j]][id[i][j]] = 1;
      if (i - 1 >= 1)
        dis[id[i][j]][id[i - 1][j]] = dis[id[i - 1][j]][id[i][j]] = 1;
      if (j + 1 <= m)
        dis[id[i][j]][id[i][j + 1]] = dis[id[i][j + 1]][id[i][j]] = 1;
      if (j - 1 >= 1)
        dis[id[i][j]][id[i][j - 1]] = dis[id[i][j - 1]][id[i][j]] = 1;
    }
  }
  for (i = 1; i <= n; i++) {
    for (j = 1; j <= m; j++) {
      if (arr[i][j] == '#') {
        if (i + 1 <= n)
          dis[id[i][j]][id[i + 1][j]] = dis[id[i + 1][j]][id[i][j]] = 9999;
        if (i - 1 >= 1)
          dis[id[i][j]][id[i - 1][j]] = dis[id[i - 1][j]][id[i][j]] = 9999;
        if (j + 1 <= m)
          dis[id[i][j]][id[i][j + 1]] = dis[id[i][j + 1]][id[i][j]] = 9999;
        if (j - 1 >= 1)
          dis[id[i][j]][id[i][j - 1]] = dis[id[i][j - 1]][id[i][j]] = 9999;
      }
    }
  }
  for (long long ouo = 0; ouo < k; ouo++) {
    for (i = 0; i < k; i++) {
      for (j = 0; j < k; j++) {
        dis[i][j] = min(dis[i][j], dis[i][ouo] + dis[ouo][j]);
      }
    }
  }
  long long ans = 0;
  for (i = 0; i < k; i++) {
    for (j = 0; j < k; j++) {
      if (dis[i][j] < 9999) {
        ans = max(ans, dis[i][j]);
      }
    }
  }
  cout << ans << '\n';
  return 0;
}
