#include <bits/stdc++.h>
using namespace std;
int X[] = {0, 0, 1, -1};
int Y[] = {1, -1, 0, 0};
bool valido(int i, int j, vector<vector<char>> matrix) {
  if (i < 0 || i >= matrix.size() || j < 0 || j >= matrix[0].size())
    return false;
  return matrix[i][j] == '.';
}
void bfs(int i, int j, int& resp, vector<vector<char>> matrix) {
  queue<pair<pair<int, int>, int>> q;
  q.push(pair<pair<int, int>, int>(pair<int, int>(i, j), 0));
  while (!q.empty()) {
    auto u = q.front();
    q.pop();
    i = u.first.first;
    j = u.first.second;
    int qt = u.second;
    for (int x = 0; x < 4; x++) {
      int ii = i + X[x];
      int jj = j + Y[x];
      if (valido(ii, jj, matrix)) {
        matrix[ii][jj] = '#';
        resp = max(resp, qt + 1);
        q.push(pair<pair<int, int>, int>(pair<int, int>(ii, jj), qt + 1));
      }
    }
  }
}
int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  vector<vector<char>> matrix(n, vector<char>(m));
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      scanf(" %c", &matrix[i][j]);
    }
  }
  int resp = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (matrix[i][j] != '#') bfs(i, j, resp, matrix);
    }
  }
  printf("%d\n", resp);
  return 0;
}
