#include <bits/stdc++.h>
using namespace std;
int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, -1, 1};
int H, W, maxx = -1;
char G[20][20];
int vis[20][20];
void dist(int ni, int nj, int mi, int mj, int cnt) {
  vis[ni][nj] = true;
  cnt++;
  if (ni == nj && mi == mj) {
    maxx = max(maxx, cnt);
    return;
  }
  for (int k = 0; k < 4; k++) {
    int di = ni + dx[k], dj = nj + dy[k];
    if (vis[di][dj] || G[di][dj] == '#' || di < 0 || dj < 0 || di >= H ||
        dj >= W)
      continue;
    else
      dist(di, dj, mi, mj, cnt);
    vis[di][dj] = false;
  }
}
int main() {
  cin >> H >> W;
  char G[H][W];
  for (int i = 0; i < H; i++) {
    string s;
    cin >> s;
    for (int j = 0; j < s.size(); j++) G[i][j] = s[j];
  }
  for (int ni = 0; ni <= H - 1; ni++)
    for (int nj = 0; nj <= W - 1; nj++)
      for (int mi = 0; mi <= H - 1; mi++)
        for (int mj = 0; mj <= W - 1; mj++)
          if (G[ni][nj] == '.' && G[mi][mj] == '.') dist(ni, nj, mi, mj, 0);
  cout << maxx;
}
