#include <bits/stdc++.h>
using namespace std;
int n, m, a1, a2, ns = 99999, maxl = 0;
char a[25][25];
int ok[25][25];
bool judge[25][25];
int dfs(int x, int y, int ans) {
  if (ok[x][y] < ans) return 0;
  ok[x][y] = min(ok[x][y], ans);
  if (x != n && a[x + 1][y] == '.' && judge[x + 1][y] == false) {
    judge[x][y] = true;
    dfs(x + 1, y, ans + 1);
    judge[x][y] = false;
  }
  if (x != 1 && a[x - 1][y] == '.' && judge[x - 1][y] == false) {
    judge[x][y] = true;
    dfs(x - 1, y, ans + 1);
    judge[x][y] = false;
  }
  if (y != m && a[x][y + 1] == '.' && judge[x][y + 1] == false) {
    judge[x][y] = true;
    dfs(x, y + 1, ans + 1);
    judge[x][y] = false;
  }
  if (y != 1 && a[x][y - 1] == '.' && judge[x][y - 1] == false) {
    judge[x][y] = true;
    dfs(x, y - 1, ans + 1);
    judge[x][y] = false;
  }
}
int main() {
  cin >> n >> m;
  memset(ok, false, sizeof(ok));
  memset(judge, false, sizeof(judge));
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      cin >> a[i][j];
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (a[i][j] != '#') {
        for (int k = 1; k <= n; k++)
          for (int p = 1; p <= m; p++) ok[k][p] = 999999;
        ns = -1;
        dfs(i, j, 0);
        for (int k = 1; k <= n; k++)
          for (int p = 1; p <= m; p++)
            if (a[k][p] != '#' && ok[k][p] != 999999 && k != i && p != j)
              ns = max(ns, ok[k][p]);
        if (ns != -1) {
          maxl = max(maxl, ns);
        }
      }
    }
  }
  cout << maxl << endl;
}
