#include <bits/stdc++.h>
using namespace std;
const int INF = 1000000000;
const int MOD = 1000000007;
int h, w;
string grid[25];
int vis[25][25], sol[25][25][25][25];
int solve(int a, int b, int x, int y) {
  if (a == x && b == y) return 0;
  int res1 = INF, res2 = INF, res3 = INF, res4 = INF;
  if (a + 1 < h && !vis[a + 1][b] && grid[a + 1][b] == '.') {
    vis[a + 1][b] = 1;
    res1 = 1 + solve(a + 1, b, x, y);
    vis[a + 1][b] = 0;
  }
  if (a - 1 >= 0 && !vis[a - 1][b] && grid[a - 1][b] == '.') {
    vis[a - 1][b] = 1;
    res2 = 1 + solve(a - 1, b, x, y);
    vis[a - 1][b] = 0;
  }
  if (b + 1 < w && !vis[a][b + 1] && grid[a][b + 1] == '.') {
    vis[a][b + 1] = 1;
    res3 = 1 + solve(a, b + 1, x, y);
    vis[a][b + 1] = 0;
  }
  if (b - 1 >= 0 && !vis[a][b - 1] && grid[a][b - 1] == '.') {
    vis[a][b - 1] = 1;
    res4 = 1 + solve(a, b - 1, x, y);
    vis[a][b - 1] = 0;
  }
  return min({res1, res2, res3, res4});
}
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cin >> h >> w;
  for (int i = 0; i < h; i++) {
    cin >> grid[i];
  }
  int res = 0;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      for (int x = i; x < h; x++) {
        for (int y = 0; y < w; y++) {
          if (!(i == x && j == y) && grid[i][j] == '.' && grid[x][y] == '.') {
            memset(vis, 0, sizeof(vis));
            vis[i][j] = 1;
            int cur = solve(i, j, x, y);
            if (cur != INF) {
              res = max(res, cur);
            }
          }
        }
      }
    }
  }
  cout << res << endl;
  return 0;
}
