#include <bits/stdc++.h>
using namespace std;
long long INF = 1000000;
int main() {
  long long h, w, ans = 0, tmp, start, goal;
  cin >> h >> w;
  vector<vector<char> > vec(h + 2, vector<char>(w + 2, '#'));
  long long dp[h + 2][w + 2][h + 2][w + 2];
  for (long long i = 0; i < h + 2; i++)
    for (long long j = 0; j < w + 2; j++)
      for (long long k = 0; k < h + 2; k++)
        for (long long l = 0; l < w + 2; l++) dp[i][j][k][l] = INF;
  for (long long i = 0; i < h; i++)
    for (long long j = 0; j < w; j++) {
      cin >> vec.at(i + 1).at(j + 1);
    }
  int mvx[4] = {0, -1, 0, 1}, mvy[4] = {-1, 0, 1, 0};
  for (long long i = 0; i < h; i++)
    for (long long j = 0; j < w; j++) {
      if (vec.at(i + 1).at(j + 1) == '.') {
        for (long long k = 0; k < 4; k++) {
          if (vec.at(i + 1 + mvx[k]).at(j + 1 + mvy[k]) == '.') {
            dp[i + 1][j + 1][i + 1 + mvx[k]][j + 1 + mvy[k]] = 1;
          }
        }
      }
    }
  for (long long m = 0; m < h; m++) {
    for (long long n = 0; n < w; n++) {
      for (long long i = 0; i < h; i++) {
        for (long long j = 0; j < w; j++) {
          for (long long k = 0; k < h; k++) {
            for (long long l = 0; l < w; l++) {
              dp[i + 1][j + 1][k + 1][l + 1] =
                  min(dp[i + 1][j + 1][k + 1][l + 1],
                      dp[i + 1][j + 1][m + 1][n + 1] +
                          dp[m + 1][n + 1][k + 1][l + 1]);
            }
          }
        }
      }
    }
  }
  long long mx = 0LL;
  for (long long i = 0; i < h; i++)
    for (long long j = 0; j < w; j++)
      for (long long k = 0; k < h; k++)
        for (long long l = 0; l < w; l++) {
          mx = max(mx, (dp[i + 1][j + 1][k + 1][l + 1] < INF)
                           ? dp[i + 1][j + 1][k + 1][l + 1]
                           : 0);
        }
  cout << mx << endl;
}
