#include <bits/stdc++.h>
using namespace std;
long long int power(long long int a, long long int b) {
  long long int res = 1;
  a %= 1000000007;
  assert(b >= 0);
  for (; b; b >>= 1) {
    if (b & 1) res = res * a % 1000000007;
    a = a * a % 1000000007;
  }
  return res;
}
long long int modInverse(long long int a) { return power(a, 1000000007 - 2); }
const int N = 30;
bool vis[N];
vector<int> adj[N];
char board[N + 2][N + 2];
map<pair<int, int>, int> indx;
int dist[N * N][N * N];
void solve() {
  long long int h, w;
  cin >> h >> w;
  int t = 1;
  for (int i = 1; i <= h; i++) {
    string s;
    cin >> s;
    for (int j = 0; j < s.length(); j++) {
      board[i][j + 1] = s[j];
      indx[make_pair(i, j + 1)] = t++;
    }
  }
  for (int i = 1; i <= h; i++) {
    for (int j = 1; j <= w; j++) {
      if (board[i][j] != '.') continue;
      if (board[i - 1][j] == '.') {
        adj[indx[make_pair(i, j)]].push_back(indx[make_pair(i - 1, j)]);
      }
      if (board[i + 1][j] == '.') {
        adj[indx[make_pair(i, j)]].push_back(indx[make_pair(i + 1, j)]);
      }
      if (board[i][j - 1] == '.') {
        adj[indx[make_pair(i, j)]].push_back(indx[make_pair(i, j - 1)]);
      }
      if (board[i][j + 1] == '.') {
        adj[indx[make_pair(i, j)]].push_back(indx[make_pair(i, j + 1)]);
      }
    }
  }
  for (int i = 1; i <= h * w; i++) {
    for (int j = 1; j <= h * w; j++) {
      dist[i][j] = 1e5;
    }
  }
  for (int i = 1; i <= h * w; i++) {
    dist[i][i] = 0;
    for (int j : adj[i]) dist[i][j] = 1;
  }
  for (int k = 1; k <= h * w; k++) {
    for (int i = 1; i <= h * w; i++) {
      for (int j = 1; j <= h * w; j++) {
        if (dist[i][k] + dist[k][j] < dist[i][j])
          dist[i][j] = dist[i][k] + dist[k][j];
      }
    }
  }
  int ans = 0;
  for (int i = 1; i <= h; i++) {
    for (int j = 1; j <= w; j++) {
      if (board[i][j] != '.') continue;
      for (int k = 1; k <= h; k++) {
        for (int p = 1; p <= w; p++) {
          if (board[k][p] != '.') continue;
          ans = max(ans, dist[indx[make_pair(i, j)]][indx[make_pair(k, p)]]);
        }
      }
    }
  }
  cout << ans << '\n';
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int T = 1;
  int t = 0;
  while (t++ < T) {
    solve();
  }
  cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC
       << "ms\n";
}
