#include <bits/stdc++.h>
using namespace std;
int n, m, a[30][30], vis[30][30];
int mi = 100000000, cnt = 0;
void dfs(int x, int y, int x1, int y1) {
  if (x == x1 && y == y1) {
    mi = min(mi, cnt);
    return;
  }
  if (x < 1 || x > n || y < 1 || y > m) {
    return;
  }
  if (!a[x][y]) {
    return;
  }
  if (vis[x][y]) {
    return;
  }
  vis[x][y] = 1;
  cnt++;
  dfs(x + 1, y, x1, y1);
  dfs(x - 1, y, x1, y1);
  dfs(x, y + 1, x1, y1);
  dfs(x, y - 1, x1, y1);
  cnt--;
  vis[x][y] = 0;
}
int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      char c;
      cin >> c;
      a[i][j] = c == '.' ? 1 : 0;
    }
  }
  int ans = -1;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      for (int i1 = 1; i1 <= n; i1++) {
        for (int j1 = 1; j1 <= m; j1++) {
          memset(vis, 0, sizeof(vis));
          mi = 100000000;
          cnt = 0;
          dfs(i, j, i1, j1);
          if (mi != 100000000) {
            ans = max(ans, mi);
          }
        }
      }
    }
  }
  cout << ans << endl;
}
