#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
int vx[] = {0, 1, 0, -1};
int vy[] = {1, 0, -1, 0};
int dist[21][21];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int h, w;
  cin >> h >> w;
  char field[h + 1][w + 1];
  for (int i = 0; i < h; i++)
    for (int j = 0; j < w; j++) cin >> field[i][j];
  int ans = 0;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (field[i][j] == '#') continue;
      fill(dist[0], dist[h], 1e9);
      queue<pair<int, int>> q;
      q.emplace(i, j);
      dist[i][j] = 0;
      while (!q.empty()) {
        pair<int, int> now = q.front();
        q.pop();
        for (int k = 0; k < 4; k++) {
          int ny = now.first + vy[k], nx = now.second + vx[k];
          if (0 <= ny && ny <= h && 0 <= nx && nx <= w &&
              field[ny][nx] != '#' && dist[ny][nx] == 1e9) {
            q.emplace(ny, nx);
            dist[ny][nx] = dist[now.first][now.second] + 1;
            ans = max(ans, dist[ny][nx]);
          }
        }
      }
    }
  }
  cout << ans - 1 << '\n';
  return 0;
}
