#include <bits/stdc++.h>
using namespace std;
const int INF = 10000000;
string s[20];
int h, w;
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
int d[20][20];
int maze(int sx, int sy) {
  queue<pair<int, int> > que;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) d[i][j] = INF;
  }
  que.push(pair<int, int>(sx, sy));
  d[sx][sy] = 0;
  int imax;
  while (que.size()) {
    pair<int, int> p = que.front();
    que.pop();
    for (int i = 0; i < 4; i++) {
      int nx = p.first + dx[i];
      int ny = p.second + dy[i];
      if (0 <= nx && nx < h && 0 <= ny && ny < w && s[nx][ny] == '.' &&
          d[nx][ny] == INF) {
        que.push(pair<int, int>(nx, ny));
        d[nx][ny] = d[p.first][p.second] + 1;
        if (d[nx][ny] > imax) {
          imax = d[nx][ny];
        }
      }
    }
  }
  return imax;
}
int main(void) {
  cin >> h >> w;
  for (int i = 0; i < h; i++) {
    cin >> s[i];
  }
  int r = 0;
  for (int m = 0; m < h; m++) {
    for (int n = 0; n < w; n++) {
      if (s[m][n] == '.') {
        r = max(r, maze(m, n));
      }
    }
  }
  cout << r;
  return 0;
}
