#include <bits/stdc++.h>
using namespace std;
using in = int64_t;
const double PI = 3.14159265358979323846;
const int64_t waru = 1000000007;
const in INF = 1 << 30;
using vec = vector<vector<vector<vector<int>>>>;
void chmin(int &a, int b) {
  if (a > b) {
    a = b;
  }
  return;
}
void chmax(int &a, int b) {
  if (a < b) a = b;
  return;
}
int main() {
  int h, w;
  cin >> h >> w;
  vector<vector<char>> a(h, vector<char>(w));
  for (int i = 0; i < (int)(h); i++) {
    for (int j = 0; j < (int)(w); j++) cin >> a.at(i).at(j);
  }
  int dp[22][22][22][22];
  for (int i = 0; i < (int)(22); i++)
    for (int j = 0; j < (int)(22); j++)
      for (int k = 0; k < (int)(22); k++)
        for (int l = 0; l < (int)(22); l++) dp[i][j][k][l] = 1000;
  int au[22][22][22][22];
  while (!(au == dp)) {
    for (int i = 0; i < (int)(h); i++) {
      for (int j = 0; j < (int)(w); j++) {
        for (int k = 0; k < (int)(h); k++) {
          for (int l = 0; l < (int)(w); l++) {
            if (i == k && j > l) {
              dp[i][j][k][l] = 0;
              continue;
            }
            if (i > k) {
              dp[i][j][k][l] = 0;
              continue;
            }
            if (a[i][j] == '#') {
              dp[i][j][k][l] = 0;
              continue;
            }
            if (a[k][l] == '#') {
              dp[i][j][k][l] = 0;
              continue;
            }
            if (i == k && j == l) {
              dp[i][j][k][l] = 0;
              continue;
            }
            if (l > 0)
              if (a[k][l - 1] == '.')
                chmin(dp[i][j][k][l - 1], dp[i][j][k][l] + 1);
            if (k > 0)
              if (a[k - 1][l] == '.')
                chmin(dp[i][j][k - 1][l], dp[i][j][k][l] + 1);
            if (l < w - 1)
              if (a[k][l + 1] == '.')
                chmin(dp[i][j][k][l + 1], dp[i][j][k][l] + 1);
            if (k < h - 1)
              if (a[k + 1][l] == '.')
                chmin(dp[i][j][k + 1][l], dp[i][j][k][l] + 1);
          }
        }
      }
    }
    for (int i = 0; i < (int)(22); i++)
      for (int j = 0; j < (int)(22); j++)
        for (int k = 0; k < (int)(22); k++)
          for (int l = 0; l < (int)(22); l++) au[i][j][k][l] = dp[i][j][k][l];
  }
  int ans = 0;
  for (int i = 0; i < (int)(h); i++) {
    for (int j = 0; j < (int)(w); j++) {
      for (int k = 0; k < (int)(h); k++) {
        for (int l = 0; l < (int)(w); l++) {
          if (dp[i][j][k][l] < 1000) chmax(ans, dp[i][j][k][l]);
        }
      }
    }
  }
  cout << ans;
}
