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