#include <bits/stdc++.h>
using namespace std;
int n, m;
vector<int> dx = {1, -1, 0, 0};
vector<int> dy = {0, 0, -1, 1};
vector<vector<bool>> vis;
vector<vector<char>> board;
int bfs(int x, int y) {
  vis[x][y] = true;
  int ans = 0;
  vector<vector<int>> dist(n, vector<int>(m, 0));
  queue<pair<int, int>> q;
  q.push({x, y});
  while (!q.empty()) {
    x = q.front().first;
    y = q.front().second;
    q.pop();
    for (int i = 0; i < 4; ++i) {
      if (x + dx[i] >= 0 && x + dx[i] < n && y + dy[i] >= 0 && y + dy[i] < m &&
          !vis[x + dx[i]][y + dy[i]] && board[x + dx[i]][y + dy[i]] != '#') {
        dist[x + dx[i]][y + dy[i]] = dist[x][y] + 1;
        ans = max(ans, dist[x][y] + 1);
        q.push({x + dx[i], y + dy[i]});
        vis[x + dx[i]][y + dy[i]] = true;
      }
    }
  }
  return ans;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n >> m;
  board.assign(n, vector<char>(m, ' '));
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      cin >> board[i][j];
    }
  }
  int res = 0;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      if (board[i][j] == '#') break;
      vis.assign(n, vector<bool>(m, false));
      res = max(res, bfs(i, j));
    }
  }
  cout << res;
  return 0;
}
