#include <bits/stdc++.h>
using namespace std;
int m, n;
vector<vector<char>> maze;
vector<int> dir{0, 1, 0, -1, 0};
bool safe(int x, int y) {
  return x >= 0 && x < m && y >= 0 && y < n && maze[x][y] != '#';
}
int bfs(int i, int j) {
  vector<vector<int>> flag(m, vector<int>(n, 0));
  queue<pair<int, int>> Q;
  Q.push({i, j});
  flag[i][j] = 1;
  int ret = 0;
  while (!Q.empty()) {
    auto p = Q.front();
    Q.pop();
    int x = p.first, y = p.second;
    ret = max(ret, flag[x][y]);
    for (int i = 0; i < 4; i++) {
      int nx = x + dir[i], ny = y + dir[i + 1];
      if (safe(nx, ny) && !flag[nx][ny]) {
        flag[nx][ny] = flag[x][y] + 1;
        Q.push({nx, ny});
      }
    }
  }
  return ret;
}
int main() {
  cin >> m >> n;
  maze.clear();
  maze.resize(m, vector<char>(n, '.'));
  for (int i = 0; i < m; ++i) {
    for (int j = 0; j < n; ++j) {
      cin >> maze[i][j];
    }
  }
  int ans = 0;
  for (int i = 0; i < m; ++i) {
    for (int j = 0; j < n; j++) {
      ans = max(ans, bfs(i, j) - 1);
    }
  }
  cout << ans << endl;
  return 0;
}
