#include <bits/stdc++.h>
using namespace std;
template <typename T>
const T INF = (is_same<T, int>::value ? 1e9 : 1e18);
template <typename T>
inline T mod(T n, T mod) {
  T res = n % mod;
  if (res < 0) res += mod;
  return res;
}
int vx[] = {0, 0, -1, 1};
int vy[] = {1, -1, 0, 0};
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  int n, m;
  cin >> n >> m;
  vector<vector<char>> grid(n, vector<char>(m));
  vector<vector<int>> dist(n, vector<int>(m, 0));
  vector<vector<bool>> vis(n, vector<bool>(m, false));
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> grid[i][j];
    }
  }
  function<int(int, int)> bfs = [&](int sti, int stj) {
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        dist[i][j] = 0;
        vis[i][j] = false;
      }
    }
    queue<pair<int, int>> q;
    q.emplace(sti, stj);
    vis[sti][stj] = true;
    int x = sti, y = stj;
    while (!q.empty()) {
      x = q.front().first;
      y = q.front().second;
      q.pop();
      for (int i = 0; i < 4; i++) {
        int nx = x + vx[i];
        int ny = y + vy[i];
        if (nx >= 0 and nx < n and ny >= 0 and ny < m) {
          if (!vis[nx][ny] and grid[nx][ny] == '.') {
            q.emplace(nx, ny);
            dist[nx][ny] = dist[x][y] + 1;
            vis[nx][ny] = true;
          }
        }
      }
    }
    return dist[x][y];
  };
  int ans = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      ans = max(ans, bfs(i, j));
    }
  }
  cout << ans << endl;
  return 0;
}
