#include <bits/stdc++.h>
using namespace std;
long long int pow1(long long int n, long long int p) {
  if (p == 0) return 1;
  long long int x = pow1(n, p / 2);
  x = (x * x) % 1000000007;
  if (p % 2 == 0)
    return x;
  else
    return (x * n) % 1000000007;
}
long long int h, w;
vector<vector<long long int>> v(20, vector<long long int>(20, 0));
long long int dfs(long long int i, long long int j,
                  vector<vector<long long int>> &v1, long long int a,
                  long long int b, vector<vector<long long int>> &vis) {
  if (v[i][j] == 0) return INT_MAX;
  vis[i][j] = 1;
  if (i == a && j == b) {
    v1[i][j] = 0;
    return 0;
  }
  long long int x = INT_MAX;
  if (i != h - 1) {
    if (vis[i + 1][j])
      x = min(x, v1[i + 1][j]);
    else
      x = min(x, dfs(i + 1, j, v1, a, b, vis));
  }
  if (i != 0) {
    if (vis[i - 1][j])
      x = min(x, v1[i - 1][j]);
    else
      x = min(x, dfs(i - 1, j, v1, a, b, vis));
  }
  if (j != w - 1) {
    if (vis[i][j + 1])
      x = min(x, v1[i][j + 1]);
    else
      x = min(x, dfs(i, j + 1, v1, a, b, vis));
  }
  if (j != 0) {
    if (vis[i][j - 1])
      x = min(x, v1[i][j - 1]);
    else
      x = min(x, dfs(i, j - 1, v1, a, b, vis));
  }
  v1[i][j] = x + 1;
  return x + 1;
}
int32_t main() {
  cin >> h >> w;
  for (long long int i = 0; i < h; i++) {
    for (long long int j = 0; j < w; j++) {
      char c;
      cin >> c;
      if (c == '.') v[i][j] = 1;
    }
  }
  long long int ans = 0;
  for (long long int i = 0; i < h; i++) {
    for (long long int j = 0; j < w; j++) {
      if (v[i][j] == 0) continue;
      for (long long int k = 0; k < h; k++) {
        for (long long int l = 0; l < w; l++) {
          if (v[k][l] == 0) continue;
          if (i == k && j == l) continue;
          vector<vector<long long int>> v1(h,
                                           vector<long long int>(w, INT_MAX));
          vector<vector<long long int>> vis(h, vector<long long int>(w, 0));
          long long int ans1 = dfs(i, j, v1, k, l, vis);
          ans = max(ans, ans1);
        }
      }
    }
  }
  cout << ans << "\n";
  return 0;
}
