#include <bits/stdc++.h>
#pragma GCC optimize(3)
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma comment(linker, "/stack:200000000")
using namespace std;
void io() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
}
long long h, w, cnt;
char s[25][25];
long long a[25][25];
bool vis[25][25];
long long d[4][2] = {1, 0, 0, 1, -1, 0, 0, -1};
long long f[505][505];
int MAP[300010];
void Floyd(int n) {
  for (int k = 1; k <= n; k++) {
    for (int i = 1; i <= n; i++) {
      for (int j = 1; j <= n; j++) {
        f[i][j] = min(f[i][j], f[i][k] + f[k][j]);
      }
    }
  }
}
bool chk(int x, int y) {
  return x >= 1 && x <= h && y >= 1 && y <= w && a[x][y] != -1;
}
void build() {
  for (int i = 1; i <= h; ++i) {
    for (int j = 1; j <= w; ++j) {
      MAP[100 * i + j] = ++cnt;
    }
  }
  for (int i = 1; i <= 500; ++i) {
    for (int j = 1; j <= 500; ++j) {
      f[i][j] = 2e9;
    }
  }
  for (int i = 1; i <= h; ++i) {
    for (int j = 1; j <= w; ++j) {
      if (a[i][j] == -1) continue;
      for (int k = 0; k <= 3; ++k) {
        if (!chk(i + d[k][0], j + d[k][1])) continue;
        f[MAP[100 * i + j]][MAP[100 * (i + d[k][0]) + j + d[k][1]]] = 1;
      }
    }
  }
}
int main() {
  io();
  cin >> h >> w;
  for (int i = 1; i <= h; ++i) cin >> (s[i] + 1);
  for (int i = 1; i <= h; ++i) {
    for (int j = 1; j <= w; ++j) {
      if (s[i][j] == '#') a[i][j] = -1;
    }
  }
  build();
  Floyd(cnt);
  long long maxd = 0;
  for (int i = 1; i <= cnt; ++i) {
    for (int j = 1; j <= cnt; ++j) {
      if (f[i][j] >= 2e9) continue;
      maxd = max(maxd, f[i][j]);
    }
  }
  cout << maxd;
}
