#include <bits/stdc++.h>
using namespace std;
vector<vector<int>> dirs = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};
int bfs(vector<vector<char>>& matrix, int row, int col) {
  int n = matrix.size();
  int m = matrix[0].size();
  vector<vector<bool>> used(matrix.size(),
                            vector<bool>(matrix[0].size(), false));
  queue<tuple<int, int, int>> q;
  q.push({row, col, 0});
  used[row][col] = true;
  int res = 0;
  while (q.size() > 0) {
    auto current = q.front();
    q.pop();
    int r = get<0>(current);
    int c = get<1>(current);
    int val = get<2>(current);
    res = max(res, val);
    for (auto dir : dirs) {
      int nextRow = r + dir[0];
      int nextCol = c + dir[1];
      if (nextRow < n && nextCol < m && nextRow >= 0 && nextCol >= 0 &&
          matrix[nextRow][nextCol] == '.' && !used[nextRow][nextCol]) {
        q.push({nextRow, nextCol, val + 1});
        used[nextRow][nextCol] = true;
      }
    }
  }
  return res;
}
int main() {
  int n, m;
  cin >> n >> m;
  vector<vector<char>> matrix(n, vector<char>(m, ' '));
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> matrix[i][j];
    }
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (matrix[i][j] != '#') {
        ans = max(ans, bfs(matrix, i, j));
      }
    }
  }
  cout << ans;
}
