#include <bits/stdc++.h>
using namespace std;
long long int gcd(long long int a, long long int b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  long long int h, w;
  cin >> h >> w;
  long long int dp[40][40] = {0};
  for (long long int i = 1; i <= h; i++) {
    for (long long int j = 1; j <= w; j++) {
      char x;
      cin >> x;
      if (x == '.')
        dp[i][j] = 1;
      else
        dp[i][j] = 2;
    }
  }
  long long int sp[500][500] = {0};
  for (long long int i = 1; i <= h * w; i++) {
    for (long long int j = 1; j <= h * w; j++) {
      sp[i][j] = 1000000007;
    }
  }
  for (long long int i = 1; i <= h; i++) {
    for (long long int j = 1; j <= w; j++) {
      long long int k = (i - 1) * w + j;
      if (dp[i + 1][j] == 1) {
        long long int r = (i)*w + j;
        sp[k][r] = 1;
      }
      if (dp[i][j - 1] == 1) {
        long long int r = (i - 1) * w + j - 1;
        sp[k][r] = 1;
      }
      if (dp[i - 1][j] == 1) {
        long long int r = (i - 2) * w + j;
        sp[k][r] = 1;
      }
      if (dp[i][j + 1] == 1) {
        long long int r = (i - 1) * w + j + 1;
        sp[k][r] = 1;
      }
    }
  }
  for (long long int i = 1; i <= h * w; i++) {
    for (long long int j = 1; j <= h * w; j++) {
      if (i == j) sp[i][j] = 0;
    }
  }
  long long int ans = 0;
  for (long long int k = 1; k <= h * w; k++)
    for (long long int i = 1; i <= h * w; i++)
      for (long long int j = 1; j <= h * w; j++) {
        sp[i][j] = min(sp[i][j], sp[i][k] + sp[k][j]);
        if (sp[i][j] == 1000000007) continue;
      }
  for (long long int i = 1; i <= h * w; i++)
    for (long long int j = 1; j <= h * w; j++) {
      if (sp[i][j] == 1000000007) continue;
      ans = max(ans, sp[i][j]);
    }
  cout << ans;
}
