#include <bits/stdc++.h>
using namespace std;
long long w, h;
char arr[25][25];
long long vis[25][25];
long long xx[] = {+1, 0, -1, 0};
long long yy[] = {0, +1, 0, -1};
long long check(long long i, long long j) {
  if (i < 0 or i >= h or j < 0 or j >= w or arr[i][j] == '#') return 0;
  return 1;
}
long long bfs(long long i, long long j) {
  long long mx = -1;
  deque<pair<long long, long long>> dq;
  memset(vis, -1, sizeof(vis));
  dq.push_back({i, j});
  vis[i][j] = 0;
  while (dq.size()) {
    long long px = dq.front().first;
    long long py = dq.front().second;
    dq.pop_front();
    for (long long i = 0; i < 4; i++) {
      long long nx = px + xx[i];
      long long ny = py + yy[i];
      if (check(nx, ny) != 0 and vis[nx][ny] == -1 and arr[i][j] != '#') {
        vis[nx][ny] = vis[px][py] + 1;
        mx = max(vis[nx][ny], mx);
        dq.push_back({nx, ny});
      }
    }
  }
  return mx;
}
int main() {
  ios_base::sync_with_stdio(0);
  long long t = 1;
  long long T = t;
  while (t--) {
    cin >> h >> w;
    for (long long i = 0; i < h; i++) {
      for (long long j = 0; j < w; j++) {
        cin >> arr[i][j];
      }
    }
    long long mx = 0;
    for (long long i = 0; i < h; i++) {
      for (long long j = 0; j < w; j++) {
        if (arr[i][j] != '#') {
          mx = max(mx, bfs(i, j));
        }
      }
    }
    cout << mx << '\n';
  }
  return 0;
}
