#include <bits/stdc++.h>
#pragma GCC optimize("-O3")
using namespace std;
long long MOD = 1e9 + 7;
long long exp(long long n, long long e) {
  if (e == 0) return 1;
  long long temp = exp((n * n) % MOD, e / 2);
  return e % 2 == 0 ? temp : (temp * n) % MOD;
}
int n, m;
long long cal(vector<string> &arr, int x, int y) {
  vector<pair<long long, long long> > frontier;
  vector<vector<long long> > dist(21, vector<long long>(21, -1));
  frontier.push_back(pair<long long, long long>(x, y));
  long long ans = 0;
  dist[x][y] = 0;
  while (frontier.size() > 0) {
    vector<pair<long long, long long> > next;
    for (int i = 0; i < ((long long)(frontier).size()); i++) {
      int a = frontier[i].first;
      int b = frontier[i].second;
      ans = max(ans, dist[a][b]);
      if (a > 1 && dist[a - 1][b] == -1 && arr[a - 1][b] == '.') {
        next.push_back(pair<long long, long long>(a - 1, b));
        dist[a - 1][b] = dist[a][b] + 1;
      }
      if (b > 1 && dist[a][b - 1] == -1 && arr[a][b - 1] == '.') {
        next.push_back(pair<long long, long long>(a, b - 1));
        dist[a][b - 1] = dist[a][b] + 1;
      }
      if (a < n && dist[a + 1][b] == -1 && arr[a + 1][b] == '.') {
        next.push_back(pair<long long, long long>(a + 1, b));
        dist[a + 1][b] = dist[a][b] + 1;
      }
      if (b < m && dist[a][b + 1] == -1 && arr[a][b + 1] == '.') {
        next.push_back(pair<long long, long long>(a, b + 1));
        dist[a][b + 1] = dist[a][b] + 1;
      }
    }
    frontier = next;
  }
  return ans;
}
void solve() {
  cin >> n >> m;
  vector<string> arr(n + 1);
  for (int i = 1; i <= n; i++) {
    cin >> arr[i];
    arr[i] = "a" + arr[i];
  }
  long long ans = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      ans = max(ans, cal(arr, i, j));
    }
  }
  cout << ans << endl;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
