#include <bits/stdc++.h>
using namespace std;
bool flag[25][25];
int path[25][25][25][25];
int startH, startW;
int H, W;
char S[25][25];
void dfs(int i, int j, int n) {
  flag[i][j] = true;
  path[startH][startW][i][j] = min(path[startH][startW][i][j], n);
  if (i >= 1 && S[i - 1][j] == '.' && flag[i - 1][j] == false)
    dfs(i - 1, j, n + 1);
  if (i <= H - 2 && S[i + 1][j] == '.' && flag[i + 1][j] == false)
    dfs(i + 1, j, n + 1);
  if (j >= 1 && S[i][j - 1] == '.' && flag[i][j - 1] == false)
    dfs(i, j - 1, n + 1);
  if (j <= W - 2 && S[i][j + 1] == '.' && flag[i][j + 1] == false)
    dfs(i, j + 1, n + 1);
  flag[i][j] = false;
}
int main() {
  cin >> H >> W;
  for (int i = 0; i < (int)(H); i++) {
    for (int j = 0; j < (int)(W); j++) cin >> S[i][j];
  }
  int INF = 1000;
  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++) path[i][j][k][l] = INF;
      }
    }
  }
  for (int i = 0; i < (int)(H); i++) {
    for (int j = 0; j < (int)(W); j++) {
      if (S[i][j] == '#') continue;
      startH = i, startW = j;
      dfs(i, j, 0);
    }
  }
  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 (S[i][j] == '.' && S[k][l] == '.')
            ans = max(ans, path[i][j][k][l]);
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}
