#include <bits/stdc++.h>
using namespace std;
static const int MAX = 20;
static const int NIL = -1;
int n, m;
char s[MAX][MAX + 1];
int d[MAX][MAX + 1];
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
int ans;
void dfs(int x, int y, int k) {
  for (int l = 0; l < (int)(n); l++) {
    for (int g = 0; g < (int)(m); g++) {
      d[l][g] = NIL;
    }
  }
  queue<pair<int, int> > S;
  S.push(make_pair(x, y));
  d[x][y] = 0;
  int maxL = 0;
  int maxX = x;
  int maxY = y;
  while (!S.empty()) {
    int X = S.front().first;
    int Y = S.front().second;
    S.pop();
    for (int l = 0; l < (int)(4); l++) {
      int nx = X + dx[l];
      int ny = Y + dy[l];
      if (0 <= nx && nx < n && 0 <= ny && ny < m && s[nx][ny] != '#' &&
          d[nx][ny] == NIL) {
        if (k == 1) s[nx][ny] = '#';
        S.push(make_pair(nx, ny));
        d[nx][ny] = d[X][Y] + 1;
        if (maxL < d[nx][ny]) {
          maxL = d[nx][ny];
          maxX = nx;
          maxY = ny;
        }
      }
    }
  }
  if (k == 1) ans = max(ans, maxL);
  if (k == 0) dfs(maxX, maxY, 1);
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < (int)(n); i++) {
    for (int j = 0; j < (int)(m); j++) {
      cin >> s[i][j];
    }
  }
  int cnt = 0;
  ans = 0;
  for (int i = 0; i < (int)(n); i++) {
    for (int j = 0; j < (int)(m); j++) {
      if (s[i][j] == '.') {
        dfs(i, j, 0);
      }
    }
  }
  cout << ans << endl;
  return 0;
}
