#include <bits/stdc++.h>
using namespace std;
const long long N = 2e5 + 5;
const long long MOD = 1e9 + 7;
long long ans, n, m;
char a[25][25];
long long dist1[25][25], dist2[25][25];
void dfs1(long long x, long long y, long long d) {
  dist1[x][y] = d;
  if (x - 1 >= 0 && dist1[x - 1][y] > d + 1 && a[x - 1][y] != '#')
    dfs1(x - 1, y, d + 1);
  if (x + 1 < n && dist1[x + 1][y] > d + 1 && a[x + 1][y] != '#')
    dfs1(x + 1, y, d + 1);
  if (y - 1 >= 0 && dist1[x][y - 1] > d + 1 && a[x][y - 1] != '#')
    dfs1(x, y - 1, d + 1);
  if (y + 1 < m && dist1[x][y + 1] > d + 1 && a[x][y + 1] != '#')
    dfs1(x, y + 1, d + 1);
}
void dfs2(long long x, long long y, long long d) {
  dist2[x][y] = d;
  if (x - 1 >= 0 && dist2[x - 1][y] > d + 1 && a[x - 1][y] != '#')
    dfs2(x - 1, y, d + 1);
  if (x + 1 < n && dist2[x + 1][y] > d + 1 && a[x + 1][y] != '#')
    dfs2(x + 1, y, d + 1);
  if (y - 1 >= 0 && dist2[x][y - 1] > d + 1 && a[x][y - 1] != '#')
    dfs2(x, y - 1, d + 1);
  if (y + 1 < m && dist2[x][y + 1] > d + 1 && a[x][y + 1] != '#')
    dfs2(x, y + 1, d + 1);
}
void calc(long long x, long long y) {
  dfs1(x, y, 0);
  long long mx = dist1[x][y], nodex = x, nodey = y;
  for (long long i = 0; i < n; i++)
    for (long long j = 0; j < m; j++)
      if (dist1[i][j] < 1e12 && dist1[i][j] > mx)
        mx = dist1[i][j], nodex = i, nodey = j;
  dfs2(nodex, nodey, 0);
  mx = dist2[nodex][nodey];
  for (long long i = 0; i < n; i++)
    for (long long j = 0; j < m; j++)
      if (dist2[i][j] < 1e12 && dist2[i][j] > mx) mx = dist2[i][j];
  ans = max(ans, mx);
  return;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> n >> m;
  for (long long i = 0; i < 25; i++)
    for (long long j = 0; j < 25; j++) dist1[i][j] = dist2[i][j] = 1e12;
  for (long long i = 0; i < n; i++) cin >> a[i];
  for (long long i = 0; i < n; i++) {
    for (long long j = 0; j < m; j++) {
      if (dist1[i][j] < 1e4 || a[i][j] == '#') continue;
      calc(i, j);
    }
  }
  cout << ans;
}
