#include <bits/stdc++.h>
using namespace std;
inline long long read() {
  long long x = 0;
  int f = 1;
  char c = getchar();
  for (; !isdigit(c); c = getchar())
    if (c == '-') f = -f;
  for (; isdigit(c); c = getchar()) x = x * 10 + (c - '0');
  return x * f;
}
inline void out(int x) {
  if (x >= 10) out(x / 10);
  putchar(x % 10 + '0');
}
const int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
int n, m, d[22][22][22][22];
char c[22][22];
int main() {
  queue<pair<int, int> > q;
  cin >> n >> m;
  for (int i = (0); i < (n); i++)
    for (int j = (0); j < (m); j++) cin >> c[i][j];
  for (int i1 = (0); i1 < (n); i1++)
    for (int j1 = (0); j1 < (m); j1++)
      for (int i2 = (0); i2 < (n); i2++)
        for (int j2 = (0); j2 < (m); j2++) d[i1][j1][i2][j2] = 1e9;
  for (int i = (0); i < (n); i++)
    for (int j = (0); j < (m); j++) {
      q.push(make_pair(i, j));
      d[i][j][i][j] = 0;
      while (!q.empty()) {
        int x = q.front().first, y = q.front().second;
        q.pop();
        for (int k = (0); k < (4); k++) {
          int nx = x + dx[k], ny = y + dy[k];
          if (nx < 0 || nx >= n || ny < 0 || ny >= m || c[nx][ny] == '#')
            continue;
          if (d[i][j][nx][ny] == 1e9) {
            d[i][j][nx][ny] = d[i][j][x][y] + 1;
            q.push(make_pair(nx, ny));
          }
        }
      }
    }
  int ans = 0;
  for (int i1 = (0); i1 < (n); i1++)
    for (int j1 = (0); j1 < (m); j1++)
      for (int i2 = (0); i2 < (n); i2++)
        for (int j2 = (0); j2 < (m); j2++)
          if (d[i1][j1][i2][j2] != 1e9) ans = max(ans, d[i1][j1][i2][j2]);
  cout << ans << endl;
  return 0;
}
