#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O2")
const long long mod = 1e9 + 7;
const double PI = acos(-1);
long long power(long long a, long long b, long long m = mod) {
  long long ans = 1;
  a = a % m;
  while (b > 0) {
    if (b & 1) ans = (1ll * a * ans) % m;
    b >>= 1;
    a = (1ll * a * a) % m;
  }
  return ans;
}
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
long long lcm(long long x, long long y) { return (x * y) / gcd(x, y); }
bool isprime(long long n) {
  if (n < 2) return 0;
  long long i = 2;
  while (i * i <= n) {
    if (n % i == 0) return 0;
    i++;
  }
  return 1;
}
bool isPowerOfTwo(long long x) { return x && (!(x & (x - 1))); }
double distform(long long x, long long y, long long z, long long w) {
  return sqrt(1. * pow(x - z, 2) + 1. * pow(y - w, 2));
}
const long long MAXN = 2e5 + 10;
const long long inf = 1e18;
long long intlog(double base, double x) {
  return (long long)(log(x) / log(base));
}
void read(vector<long long>& a) {
  for (long long i = 0; i < ((long long)(a).size()); ++i) {
    cin >> a[i];
  }
}
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  long long n, m;
  cin >> n >> m;
  string s[n];
  long long ans = 0;
  for (long long i = 0; i < n; ++i) cin >> s[i];
  queue<pair<long long, pair<long long, long long>>> q;
  for (long long j = 0; j < n; ++j) {
    for (long long i = 0; i < m; ++i) {
      if (s[j][i] == '.') {
        q.push({j, {i, 0}});
      }
      vector<vector<long long>> vis(n, vector<long long>(m, 0));
      while (!q.empty()) {
        long long x = q.front().first;
        long long y = q.front().second.first;
        long long l = q.front().second.second;
        q.pop();
        if (vis[x][y])
          continue;
        else
          vis[x][y] = 1;
        if (x > 0 && s[x - 1][y] == '.') q.push({x - 1, {y, l + 1}});
        if (x < m - 1 && s[x + 1][y] == '.') q.push({x + 1, {y, l + 1}});
        if (y > 0 && s[x][y - 1] == '.') q.push({x, {y - 1, l + 1}});
        if (y < m - 1 && s[x][y + 1] == '.') q.push({x, {y + 1, l + 1}});
        ans = max(ans, l);
      }
    }
  }
  cout << ans << "\n";
}
