#include <bits/stdc++.h>
using namespace std;
int visit[30][30], X[5] = {0, 1, 0, -1}, Y[5] = {1, 0, -1, 0}, ans = 0, H, W;
char s[30][30];
struct node {
  int x, y, sum;
};
queue<node> q;
void BFS(int sx, int sy, int ex, int ey) {
  int x1, y1, p = 0;
  node M, M1;
  while (!q.empty()) q.pop();
  M.x = sx;
  M.y = sy;
  M.sum = 0;
  visit[sx][sy] = -2;
  q.push(M);
  while (!q.empty()) {
    M = q.front();
    q.pop();
    for (int i = 0; i < 4; i++) {
      x1 = M.x + X[i];
      y1 = M.y + Y[i];
      if (x1 >= 1 && x1 <= H && y1 >= 1 && y1 <= W && visit[x1][y1] == 0) {
        if (x1 == ex && y1 == ey) {
          p = 1;
          ans = M.sum + 1;
          break;
        } else {
          M1.x = M.x + X[i];
          M1.y = M.y + Y[i];
          M1.sum = M.sum + 1;
          visit[x1][y1] = -2;
          q.push(M1);
        }
      }
    }
    if (p == 1) break;
  }
}
void Clear() {
  int i, j;
  for (i = 1; i <= H; i++)
    for (j = 1; j <= W; j++) {
      if (s[i][j] == '#')
        visit[i][j] = -1;
      else
        visit[i][j] = 0;
    }
}
int main() {
  int i, j, t, k, x, Max = 0;
  cin >> H >> W;
  for (i = 1; i <= H; i++)
    for (j = 1; j <= W; j++) scanf(" %c", &s[i][j]);
  for (i = 1; i <= H; i++)
    for (j = 1; j <= W; j++) {
      x = j + 1;
      for (t = i; t <= H; t++) {
        for (k = x; k <= W; k++) {
          if (visit[i][j] != -1 && visit[t][k] != -1 &&
              (visit[i][j] == 0 || visit[t][k] == 0)) {
            Clear();
            BFS(i, j, t, k);
            if (ans > Max) {
              Max = ans;
            }
          }
        }
        x = 1;
      }
    }
  cout << Max << endl;
  return 0;
}
