#include <bits/stdc++.h>
using namespace std;
bool scope[22][22];
int pepe[22][22];
char S[22][22];
int num = 0;
void wkwk(int i, int j) {
  scope[i][j] = false;
  if (scope[i + 1][j]) {
    num++;
    wkwk(i + 1, j);
  }
  if (scope[i][j + 1]) {
    num++;
    wkwk(i, j + 1);
  }
  if (scope[i - 1][j]) {
    num++;
    wkwk(i - 1, j);
  }
  if (scope[i][j - 1]) {
    num++;
    wkwk(i, j - 1);
  }
  scope[i][j] = true;
  pepe[i][j] = min(pepe[i][j], num);
  num--;
}
int main() {
  int h, w;
  int ans = 0;
  cin >> h >> w;
  for (int i = 0; i < 22; i++)
    for (int j = 0; j < 22; j++) scope[i][j] = false;
  for (int i = 0; i < 22; i++)
    for (int j = 0; j < 22; j++) S[i][j] = '#';
  for (int i = 1; i < h + 1; i++)
    for (int j = 1; j < w + 1; j++) {
      cin >> S[i][j];
      if (S[i][j] == '.') scope[i][j] = true;
    }
  for (int i = 1; i < h + 1; i++)
    for (int j = 1; j < w + 1; j++) {
      if (scope[i][j]) {
        for (int k = 0; k < 22; k++)
          for (int o = 0; o < 22; o++) pepe[k][o] = 100000;
        wkwk(i, j);
        for (int k = 0; k < 22; k++)
          for (int o = 0; o < 22; o++)
            if (pepe[k][o] != 100000) ans = max(pepe[k][o], ans);
        num = 0;
      } else
        continue;
    }
  cout << ans << endl;
}
