#include <bits/stdc++.h>
using namespace std;
using PII = pair<int, int>;
const vector<int> dx = {1, 0, -1, 0};
const vector<int> dy = {0, 1, 0, -1};
int h, w;
vector<string> board;
int inside(int y, int x) {
  if (0 <= y && y < h && 0 <= x && x < w) {
    return true;
  } else {
    return false;
  }
}
int calc(int sy, int sx, int gy, int gx) {
  vector<vector<int>> walk(h, vector<int>(w, -1));
  if (sy == gy && sx == gx) {
    return 0;
  }
  queue<PII> que;
  walk[sy][sx] = 0;
  que.push(make_pair(sy, sx));
  int y, x, ny, nx;
  while (!que.empty()) {
    tie(y, x) = que.front();
    que.pop();
    int n_walk = walk[y][x];
    if (y == gy && x == gx) {
      return n_walk;
    }
    for (int i = 0; i < 4; i++) {
      ny = y + dy[i];
      nx = x + dx[i];
      if (!inside(ny, nx)) {
        continue;
      }
      if (board[ny][nx] == '#') {
        continue;
      }
      if (walk[ny][nx] != -1) {
        continue;
      }
      walk[ny][nx] = n_walk + 1;
      que.push(make_pair(ny, nx));
    }
  }
  return 1e6;
}
int main() {
  cin >> h >> w;
  board.assign(h, "");
  for (int i = 0; i < h; i++) {
    cin >> board[i];
  }
  int ans = 0;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (board[i][j] == '#') {
        continue;
      }
      for (int k = 0; k < h; k++) {
        for (int l = 0; l < w; l++) {
          if (board[k][l] == '#') {
            continue;
          }
          int tmp = calc(i, j, k, l);
          if (tmp > ans) {
            ans = tmp;
          }
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}
