#include <bits/stdc++.h>
using namespace std;
const int maxn = 2000005;
int mp[405][405];
int vis[405][405];
int dis[405][405];
char a[30][30];
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int i = 0; i < n * m; i++) {
    for (int j = 0; j < n * m; j++) dis[i][j] = maxn;
    dis[i][i] = 0;
  }
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++)
      if (a[i][j] == '.') {
        if (i > 0 && a[i - 1][j] == '.')
          dis[(i - 1) * m + j][i * m + j] = 1,
                                       dis[(i)*m + j][(i - 1) * m + j] = 1;
        if ((i + 1) < n && a[i + 1][j] == '.')
          dis[(i + 1) * m + j][i * m + j] = 1,
                                       dis[(i)*m + j][(i + 1) * m + j] = 1;
        if (j > 0 && a[i][j - 1] == '.')
          dis[i * m + j][(i)*m + j - 1] = 1, dis[(i)*m + j - 1][(i)*m + j] = 1;
        if ((j + 1) < m && a[i][j + 1] == '.')
          dis[i * m + j][(i)*m + j + 1] = 1, dis[(i)*m + j + 1][(i)*m + j] = 1;
      }
  for (int i = 0; i < (n * m); i++) {
    if (a[i / m][i % m] == '#') continue;
    for (int j = 0; j < (n * m); j++) {
      if (a[j / m][j % m] == '#') continue;
      for (int l = 0; l < (n * m); l++) {
        if (a[l / m][l % m] == '#') continue;
        if (dis[i][j] > dis[i][l] + dis[l][j]) {
          dis[i][j] = dis[i][l] + dis[l][j];
        }
      }
    }
  }
  for (int i = 0; i < (n * m); i++) {
    if (a[i / m][i % m] == '#') continue;
    for (int j = 0; j < (n * m); j++) {
      if (a[j / m][j % m] == '#') continue;
      for (int l = 0; l < (n * m); l++) {
        if (a[l / m][l % m] == '#') continue;
        if (dis[i][j] > dis[i][l] + dis[l][j]) {
          dis[i][j] = dis[i][l] + dis[l][j];
        }
      }
    }
  }
  int minn = 0;
  for (int i = 0; i < (n * m); i++) {
    if (a[i / m][i % m] == '#') continue;
    for (int j = 0; j < (n * m); j++) {
      if (a[j / m][j % m] == '#') continue;
      if (dis[i][j] < 10000) minn = max(minn, dis[i][j]);
    }
  }
  cout << minn << endl;
}
