#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
const ll MOD = 1e9 + 7;
int H, W;
char maze[20][20];
int d[20][20];
int bfs(P s, P g) {
  queue<P> q;
  int dx[4] = {1, 0, -1, 0};
  int dy[4] = {0, 1, 0, -1};
  int i, j;
  P p;
  for (i = 0; i <= H - 1; i++) {
    for (j = 0; j <= W - 1; j++) {
      d[i][j] = MOD;
    }
  }
  if (s == g) {
    return 0;
  }
  q.push(s);
  while (q.size()) {
    p = q.front();
    q.pop();
    for (i = 0; i <= 3; i++) {
      int nx = p.first + dx[i];
      int ny = p.second + dy[i];
      if (nx >= 0 && ny >= 0 && nx < H && ny < W && d[nx][ny] == MOD &&
          maze[nx][ny] == '.') {
        q.push(P(nx, ny));
        d[nx][ny] = d[p.first][p.second] + 1;
      }
    }
  }
  return d[g.first][g.second];
}
int main(void) {
  int i, j, k, l;
  int ans = 0;
  cin >> H >> W;
  for (i = 0; i <= H - 1; i++) {
    for (j = 0; j <= W - 1; j++) {
      cin >> maze[i][j];
    }
  }
  for (i = 0; i <= H - 1; i++) {
    for (j = 0; j <= W - 1; j++) {
      for (k = 0; k <= H - 1; k++) {
        for (l = 0; l <= W - 1; l++) {
          if (maze[i][j] == '.' && maze[k][l] == '.') {
            ans = max(bfs(P(i, j), P(k, l)), ans);
          }
        }
      }
    }
  }
  cout << ans << endl;
}
