#include <bits/stdc++.h>
using namespace std;
inline int gi() {
  int f = 1, x = 0;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') x = x * 10 + (c ^ 48), c = getchar();
  return f * x;
}
inline long long gl() {
  long long f = 1, x = 0;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') x = x * 10 + (c ^ 48), c = getchar();
  return f * x;
}
const int maxn = 25;
int n, k, h, w, vis[maxn][maxn], ans;
char s[maxn][maxn];
const int dx[] = {1, -1, 0, 0}, dy[] = {0, 0, 1, -1};
int minn;
void dfs(int x, int y, int xx, int yy, int now) {
  if (x == xx && y == yy) {
    minn = min(minn, now);
    return;
  }
  for (int i = 0; i < 4; i += 1) {
    int xxx = x + dx[i], yyy = y + dy[i];
    if (s[xxx][yyy] == '.' && !vis[xxx][yyy]) {
      vis[xxx][yyy] = 1;
      dfs(xxx, yyy, xx, yy, now + 1);
      vis[xxx][yyy] = 0;
    }
  }
}
int main() {
  h = gi(), w = gi();
  for (int i = 1; i <= h; i += 1) scanf("%s", s[i] + 1);
  for (int i = 1; i <= h; i += 1) {
    for (int j = 1; j <= w; j += 1) {
      for (int ii = 1; ii <= h; ii += 1) {
        for (int jj = 1; jj <= w; jj += 1) {
          memset(vis, 0, sizeof(vis));
          vis[i][j] = 1;
          minn = 100000000;
          dfs(i, j, ii, jj, 0);
          if (minn != 100000000) ans = max(ans, minn);
        }
      }
    }
  }
  printf("%d\n", ans);
  return 0;
}
