#include <bits/stdc++.h>
using namespace std;
const static long long MOD = 1e9 + 7;
int main(int argc, char *argv[]) {
  int h, w;
  cin >> h >> w;
  char board[21][21];
  bool visited[21][21];
  for (long long i = 0; i < h; i++) {
    for (long long j = 0; j < w; j++) {
      cin >> board[i][j];
      visited[i][j] = false;
    }
  }
  int ans = 0;
  queue<tuple<int, int, int>> q;
  for (long long i = 0; i < h; i++) {
    for (long long j = 0; j < w; j++) {
      int dist = 0;
      q.push(make_tuple(i, j, 0));
      visited[i][j] = true;
      while (!q.empty()) {
        tuple<int, int, int> front = q.front();
        q.pop();
        int x = get<0>(front);
        int y = get<1>(front);
        int d = get<2>(front);
        for (int dx = -1; dx <= 1; ++dx) {
          for (int dy = -1; dy <= 1; ++dy) {
            if (!((dx == -1 && dy == 0) || (dx == 1 && dy == 0) ||
                  (dx == 0 && dy == -1) || (dx == 0 && dy == 1)))
              continue;
            int nx = x + dx;
            int ny = y + dy;
            if (nx < 0 || nx >= h || ny < 0 || ny >= w) continue;
            if (board[nx][ny] == '#') continue;
            if (visited[nx][ny]) continue;
            visited[nx][ny] = true;
            q.push(make_tuple(nx, ny, d + 1));
            dist = d + 1;
          }
        }
      }
      ans = max(ans, dist);
      for (long long k = 0; k < h; k++) {
        for (long long l = 0; l < w; l++) {
          visited[k][l] = false;
        }
      }
    }
  }
  cout << ans << endl;
}
