#include <bits/stdc++.h>
using namespace std;
int bfs(vector<vector<char>> grid, int n, int m, int a, int b) {
  bool visited[n][m];
  int dist[n][m];
  int dy[4] = {-1, 1, 0, 0}, dx[4] = {0, 0, -1, 1};
  deque<pair<int, int>> queue;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      visited[i][j] = false;
      dist[i][j] = 0;
    }
  }
  visited[a][b] = 0;
  queue.push_back(make_pair(a, b));
  int res = 0;
  while (!queue.empty()) {
    auto p = queue.front();
    queue.pop_front();
    res = max(res, dist[p.first][p.second]);
    for (int i = 0; i < 4; i++) {
      int cy = p.first + dy[i], cx = p.second + dx[i];
      if (cy >= 0 && cx >= 0 && cy < n && cx < m && !visited[cy][cx] &&
          grid[cy][cx] == '.') {
        visited[cy][cx] = true;
        dist[cy][cx] = dist[p.first][p.second] + 1;
        queue.push_back(make_pair(cy, cx));
      }
    }
  }
  return res;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, m;
  cin >> n >> m;
  vector<vector<char>> grid;
  for (int i = 0; i < n; i++) {
    vector<char> curr;
    grid.push_back(curr);
    for (int j = 0; j < m; j++) {
      char now;
      cin >> now;
      grid[i].push_back(now);
    }
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) ans = max(ans, bfs(grid, n, m, i, j));
  }
  cout << ans << '\n';
  return 0;
}
