#include <bits/stdc++.h>
using namespace std;
int n, m;
int d[25][25][25][25];
char c[25][25];
int d1[4] = {0, 0, 1, -1};
int d2[4] = {1, -1, 0, 0};
queue<int> q;
bool ok(int x, int y) {
  return x >= 0 && y >= 0 && x < n && y < m && c[x][y] == '.';
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) cin >> c[i][j];
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      for (int ii = 0; ii < n; ii++)
        for (int jj = 0; jj < m; jj++) d[i][j][ii][jj] = -1;
      d[i][j][i][j] = 0;
      q.push(i), q.push(j);
      while (!q.empty()) {
        int x = q.front();
        q.pop();
        int y = q.front();
        q.pop();
        for (int k = 0; k < 4; k++) {
          int xi = x + d1[k], yi = y + d2[k];
          if (ok(xi, yi) && d[i][j][xi][yi] == -1) {
            d[i][j][xi][yi] = d[i][j][x][y] + 1;
            q.push(xi);
            q.push(yi);
          }
        }
      }
    }
  }
  int res = 0;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++)
      for (int ii = 0; ii < n; ii++)
        for (int jj = 0; jj < m; jj++) res = max(res, d[i][j][ii][jj]);
  cout << res;
  return 0;
}
