#include <bits/stdc++.h>
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const int MOD = int(1e9) + 7;
using namespace std;
using pii = pair<int, int>;
bool inside(int x, int y, int w, int h) {
  return (x >= 0 && y >= 0 && x < w && y < h);
}
int dx[] = {1, 0, -1, 0};
int dy[] = {0, -1, 0, 1};
int w, h, maxv = 0;
string mas[25];
int dist[25][25];
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> h >> w;
  for (int i = 0; i < (h); i++) {
    cin >> mas[i];
  }
  queue<pii> que;
  for (int na = 0; na < (h); na++) {
    for (int su = 0; su < (w); su++) {
      if (mas[na][su] != '#') {
        memset(dist, INF, sizeof(dist));
        dist[su][na] = 0;
        que.emplace(su, na);
        while (!que.empty()) {
          int x, y;
          tie(y, x) = que.front();
          que.pop();
          for (int i = 0; i < (4); i++) {
            int nx = x + dx[i];
            int ny = y + dy[i];
            if (inside(nx, ny, w, h) && dist[ny][nx] > dist[y][x] + 1 &&
                mas[ny][nx] != '#') {
              dist[ny][nx] = dist[y][x] + 1;
              que.emplace(ny, nx);
            }
          }
        }
        for (int i = 0; i < (h); i++) {
          for (int j = 0; j < (w); j++) {
            if (dist[i][j] != INF) {
              maxv = max(maxv, dist[i][j]);
            }
          }
        }
      }
    }
  }
  cout << maxv << '\n';
  return 0;
}
