#include <bits/stdc++.h>
using namespace std;
const int maxn = 50005;
const double inf = 1e9;
int zou[4][2] = {-1, 0, 1, 0, 0, 1, 0, -1};
struct node {
  int x, y;
};
int v[25][25];
int mi;
int w, h;
char c[25][25];
int judge(int x, int y) {
  if (c[x][y] == '#') return 0;
  if (x <= 0 || x > h || y <= 0 || y > w) return 0;
  return 1;
}
void dfs(int x, int y, int s, node zd) {
  if (v[x][y] >= s || v[x][y] == -1)
    v[x][y] = s;
  else
    return;
  if (x == zd.x && y == zd.y) {
    mi = min(s, mi);
    return;
  }
  for (int k = 0; k < 4; k++) {
    node a;
    a.x = x + zou[k][0];
    a.y = y + zou[k][1];
    if (judge(a.x, a.y)) {
      dfs(a.x, a.y, s + 1, zd);
    }
  }
}
int main() {
  scanf("%d %d", &h, &w);
  for (int i = 1; i <= h; i++) {
    char ch;
    scanf("%c", &ch);
    for (int j = 1; j <= w; j++) scanf("%c", &c[i][j]);
  }
  int ma = 0;
  for (int i = 1; i <= h; i++)
    for (int j = 1; j <= w; j++) {
      if (judge(i, j)) {
        for (int ii = i; ii <= h; ii++)
          for (int jj = 1; jj <= w; jj++)
            if (judge(ii, jj)) {
              mi = 1e9;
              memset(v, -1, sizeof(v));
              node ls;
              ls.x = ii, ls.y = jj;
              dfs(i, j, 0, ls);
              ma = max(ma, mi);
            }
      }
    }
  printf("%d\n", ma);
  return 0;
}
