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