#include <bits/stdc++.h>
using namespace std;
const long long int MOD = 1e9 + 7;
long long REM(long long a) {
  a %= MOD;
  if (a < 0) a += MOD;
  return a;
}
long long ADD(long long a, long long b) { return REM(REM(a) + REM(b)); }
long long SUB(long long a, long long b) { return REM(REM(a) - REM(b)); }
long long MUL(long long a, long long b) { return REM(REM(a) * REM(b)); }
long long POT(long long n, long long k) {
  if (k == 0) return 1;
  long long ret = POT(n, k / 2);
  ret = MUL(ret, ret);
  if (k % 2) return MUL(ret, n);
  return ret;
}
long long DIV(long long a, long long b) { return MUL(a, POT(b, MOD - 2)); }
bool isPrime(long long x) {
  if (x == 1) return 0;
  for (long long i = 2; i <= sqrt(x); i++)
    if (x % i == 0) return 0;
  return 1;
}
int dx[] = {-1, 1, 0, 0};
int dy[] = {0, 0, -1, 1};
const int MAXN = 100;
int n, m;
int mat[MAXN][MAXN];
int vis[MAXN][MAXN];
int bfs(int x, int y) {
  queue<pair<pair<int, int>, int> > Q;
  Q.push(make_pair(make_pair(x, y), 0));
  int ret = 0;
  while (!Q.empty()) {
    pair<pair<int, int>, int> state = Q.front();
    Q.pop();
    int x = state.first.first, y = state.first.second, d = state.second;
    ret = max(ret, d);
    for (int i = (0); i < (4); i++) {
      int xi = x + dx[i];
      int yi = y + dy[i];
      if (xi < 0 || xi >= n || yi < 0 || yi >= m) continue;
      if (mat[xi][yi]) continue;
      if (vis[xi][yi]) continue;
      vis[xi][yi] = 1;
      Q.push(make_pair(make_pair(xi, yi), d + 1));
    }
  }
  return ret;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> m;
  for (int i = (0); i < (n); i++) {
    string s;
    cin >> s;
    for (int j = (0); j < (m); j++) {
      if (s[j] == '#') mat[i][j] = 1;
    }
  }
  int ans = 0;
  for (int i = (0); i < (n); i++) {
    for (int j = (0); j < (m); j++) {
      if (mat[i][j]) continue;
      memset(vis, 0, sizeof vis);
      ans = max(ans, bfs(i, j));
    }
  }
  cout << ans << "\n";
  return 0;
}
