#include <bits/stdc++.h>
using namespace std;
int ma = -1, mi;
void sol(int sh, int sw, int gh, int gw, vector<vector<int> > m, int dep) {
  if (sh == gh + 1 && sw == gw) mi = min(mi, dep + 1);
  if (sh == gh - 1 && sw == gw) mi = min(mi, dep + 1);
  if (sh == gh && sw + 1 == gw) mi = min(mi, dep + 1);
  if (sh == gh && sw - 1 == gw) mi = min(mi, dep + 1);
  int tmp = 0;
  if (m[sh + 1][sw] == 0) {
    m[sh + 1][sw] = -9;
    sol(sh + 1, sw, gh, gw, m, dep + 1);
    m[sh + 1][sw] = 0;
    tmp++;
  }
  if (m[sh - 1][sw] == 0) {
    m[sh - 1][sw] = -9;
    sol(sh - 1, sw, gh, gw, m, dep + 1);
    m[sh - 1][sw] = 0;
    tmp++;
  }
  if (m[sh][sw + 1] == 0) {
    m[sh][sw + 1] = -9;
    sol(sh, sw + 1, gh, gw, m, dep + 1);
    m[sh][sw + 1] = 0;
    tmp++;
  }
  if (m[sh][sw - 1] == 0) {
    m[sh][sw - 1] = -9;
    sol(sh, sw - 1, gh, gw, m, dep + 1);
    m[sh][sw - 1] = 0;
    tmp++;
  }
}
int main() {
  int a, b;
  char tmp;
  vector<vector<int> > board;
  cin >> a >> b;
  a += 2;
  b += 2;
  board.resize(a);
  for (int i = 0; i < a; i++) board[i].resize(b);
  for (int i = 0; i < a; i++) {
    board[i][0] = -9;
    board[i][b - 1] = -9;
  }
  for (int i = 0; i < b; i++) {
    board[0][i] = -9;
    board[a - 1][i] = -9;
  }
  for (int i = 1; i < a - 1; i++) {
    for (int j = 1; j < b - 1; j++) {
      cin >> tmp;
      if (tmp == '#')
        board[i][j] = -9;
      else
        board[i][j] = 0;
    }
  }
  for (int i = 1; i < a - 1; i++) {
    for (int j = 1; j < b - 1; j++) {
      if (board[i][j] != 0) continue;
      tmp = 0;
      if (board[i + 1][j] != 0 && board[i][j + 1] != 0) tmp++;
      if (board[i][j + 1] != 0 && board[i - 1][j] != 0) tmp++;
      if (board[i - 1][j] != 0 && board[i][j - 1] != 0) tmp++;
      if (board[i][j - 1] != 0 && board[i + 1][j] != 0) tmp++;
      if (tmp == 0) continue;
      for (int k = 1; k < a - 1; k++) {
        for (int l = 1; l < b - 1; l++) {
          tmp = 0;
          if (board[k + 1][l] != 0 && board[k][l + 1] != 0) tmp++;
          if (board[k][l + 1] != 0 && board[k - 1][l] != 0) tmp++;
          if (board[k - 1][l] != 0 && board[k][l - 1] != 0) tmp++;
          if (board[k][l - 1] != 0 && board[k + 1][l] != 0) tmp++;
          mi = 10000;
          if (tmp != 0) sol(i, j, k, l, board, 0);
          if (mi != 10000) ma = max(ma, mi);
        }
      }
    }
  }
  cout << ma << endl;
}
