#include <bits/stdc++.h>
using namespace std;
const int MM = 1e9;
const int MOD = MM + 7;
const long double PI = acos(-1);
const long long INF = 1e15;
int dx[8] = {-1, 0, 1, 0, -1, -1, 1, 1};
int dy[8] = {0, -1, 0, 1, -1, 1, 1, -1};
template <typename T>
T GCD(T u, T v) {
  return v ? GCD(v, u % v) : u;
}
template <typename T>
T LCM(T x, T y) {
  T gc = GCD(x, y);
  return x * y / gc;
}
const int COM_MAX = 500500;
long long fac[COM_MAX], finv[COM_MAX], inv[COM_MAX];
void init() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < COM_MAX; i++) {
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}
long long COM(int n, int k) {
  if (n < k || n < 0 || k < 0) return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
long long modpow(long long a, long long n, long long mod) {
  long long res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}
long long modinv(long long a, long long mod) { return modpow(a, mod - 2, mod); }
struct Coordinate {
  int y, x;
};
int main() {
  int H, W;
  cin >> H >> W;
  char s[22][22];
  int maxDist = 0;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      cin >> s[i][j];
    }
  }
  int dist[22][22];
  for (int Yst = 0; Yst < H; Yst++) {
    for (int Xst = 0; Xst < W; Xst++) {
      for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
          dist[i][j] = MM;
        }
      }
      queue<Coordinate> que;
      Coordinate cor;
      cor.y = Yst;
      cor.x = Xst;
      que.push(cor);
      dist[Yst][Xst] = 0;
      while (que.size()) {
        Coordinate now = que.front();
        que.pop();
        for (int i = 0; i < 4; i++) {
          int ny = now.y + dy[i];
          int nx = now.x + dx[i];
          if (0 <= ny && ny < H && 0 <= nx && nx < W) {
            if (s[ny][nx] == '.' && dist[ny][nx] > dist[now.y][now.x] + 1) {
              dist[ny][nx] = dist[now.y][now.x] + 1;
              maxDist = max(dist[ny][nx], maxDist);
              cor.y = ny;
              cor.x = nx;
              que.push(cor);
            }
          }
        }
      }
    }
  }
  cout << maxDist << endl;
}
