#include <bits/stdc++.h>
using namespace std;
long long n, m;
char a[21][21];
long long d[401];
long long dist[21][21];
long long used[21][21];
long long dx[] = {0, 0, 1, -1};
long long dy[] = {1, -1, 0, 0};
long long res = -2e18;
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> m;
  for (long long i = 0; i < n; i++)
    for (long long j = 0; j < m; j++) cin >> a[i][j];
  for (long long i = 0; i < n; i++) {
    for (long long j = 0; j < m; j++) {
      memset(dist, -1, sizeof(dist));
      memset(used, 0, sizeof(used));
      if (a[i][j] == '#') continue;
      long long qh = 0, qt = 0;
      d[qt++] = i;
      d[qt++] = j;
      used[i][j] = 1;
      dist[i][j] = 0;
      while (qh < qt) {
        long long x = d[qh++];
        long long y = d[qh++];
        for (long long k = 0; k < 4; k++) {
          long long nx = x + dx[k];
          long long ny = y + dy[k];
          if (nx < 0 || nx >= n || ny < 0 || ny >= m || a[nx][ny] == '#')
            continue;
          if (dist[nx][ny] == -1) {
            d[qt++] = nx;
            d[qt++] = ny;
            dist[nx][ny] = dist[x][y] + 1;
          }
        }
      }
      for (long long r = 0; r < n; r++)
        for (long long c = 0; c < m; c++) res = max(res, dist[r][c]);
    }
  }
  cout << res << endl;
  return 0;
}
