#include <bits/stdc++.h>
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
using namespace std;
const long long MOD = 1000000007;
const long long INF = 1LL << 60;
long long modinv(long long a, long long m) {
  long long b = m, u = 1, v = 0;
  while (b) {
    long long t = a / b;
    a -= t * b;
    swap(a, b);
    u -= t * v;
    swap(u, v);
  }
  u %= m;
  if (u < 0) u += m;
  return u;
}
long long gcd(long long a, long long b) {
  if (a < b) swap(a, b);
  if (b == 0) return a;
  unsigned r;
  while ((r = a % b)) {
    a = b;
    b = r;
  }
  return b;
}
long long lcm(long long a, long long b) {
  long long g = gcd(a, b);
  return a * g / b;
}
bool prime(long long n) {
  for (long long i = 2; i <= sqrt(n); i++) {
    if (n % i == 0) return false;
  }
  return n != 1;
}
const long double PI = 3.14159265359;
const long long MAX_N = 20;
const long long MAX_M = 20;
const long long dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
char maze[MAX_N][MAX_M + 1];
long long n, m;
long long sx, sy;
long long gx, gy;
long long dist[MAX_N][MAX_M];
long long bfs() {
  queue<pair<long long, long long> > que;
  for (long long i = 0; i < (n); i++)
    for (long long j = 0; j < (m); j++) dist[i][j] = INF;
  que.push(pair<long long, long long>(sx, sy));
  dist[sx][sy] = 0;
  while (!que.empty()) {
    pair<long long, long long> p = que.front();
    que.pop();
    if (p.first == gx && p.second == gy) break;
    for (long long i = 0; i < (4); i++) {
      long long nx = p.first + dx[i], ny = p.second + dy[i];
      if (0 <= nx && nx < n && 0 <= ny && ny < m && maze[nx][ny] != '#' &&
          dist[nx][ny] == INF) {
        que.push(pair<long long, long long>(nx, ny));
        dist[nx][ny] = dist[p.first][p.second] + 1;
      }
    }
  }
  return dist[gx][gy];
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> m;
  for (long long i = 0; i < (n); i++)
    for (long long j = 0; j < (m); j++) cin >> maze[i][j];
  long long ans = 0;
  for (long long i = 0; i < (n); i++) {
    for (long long j = 0; j < (m); j++) {
      for (long long k = 0; k < (n); k++) {
        for (long long l = 0; l < (m); l++) {
          sx = i, sy = j;
          gx = k, gy = l;
          long long tmp = bfs();
          if (tmp != INF) chmax(ans, tmp);
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}
