#include <bits/stdc++.h>
using namespace std;
const int mxn = 21;
string arr[mxn];
int dp[mxn][mxn];
int h, w;
int ans = 0;
int dis[mxn + 1][mxn + 1];
int solve(int u, int v) {
  queue<pair<int, pair<int, int>>> q;
  memset(dis, 0, sizeof dis);
  q.push({u, {v, 0}});
  int t = 14;
  while (!q.empty()) {
    int i = q.front().first;
    int j = q.front().second.first;
    int d = q.front().second.second;
    ans = max(ans, d);
    dis[i][j] = 1;
    q.pop();
    if (i + 1 < h and dis[i + 1][j] == 0 and arr[i + 1][j] == '.') {
      q.push({i + 1, {j, d + 1}});
      dis[i + 1][j] = 1;
    }
    if (j + 1 < w and dis[i][j + 1] == 0 and arr[i][j + 1] == '.') {
      q.push({i, {j + 1, d + 1}});
      dis[i][j + 1] = 1;
    }
  }
  return 0;
}
int main() {
  cin >> h >> w;
  for (int i = 0; i < h; i++) cin >> arr[i];
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (arr[i][j] == '.') solve(i, j);
    }
  }
  cout << ans;
  return 0;
}
