#include <bits/stdc++.h>
using namespace std;
long int mod = 1000000007;
template <typename T>
void debug(T arr) {
  for (auto it : arr) {
    cout << it << ' ';
  }
  cout << '\n';
}
int n, m;
vector<vector<char>> mat;
vector<vector<int>> visited, dist;
int X[] = {0, 0, 1, -1};
int Y[] = {1, -1, 0, 0};
bool check(int x, int y) {
  return (x >= 0 && x < n && y >= 0 && y < m && mat[x][y] == '.');
}
void dfs(int x, int y) {
  visited[x][y] = 1;
  for (long long i = 0; i < 4; i++) {
    int dx = x + X[i], dy = y + Y[i];
    if (check(dx, dy) && visited[dx][dy] == 0) {
      dist[dx][dy] = dist[x][y] + 1;
      dfs(dx, dy);
    } else if (check(dx, dy) && dist[dx][dy] > dist[x][y] + 1) {
      dist[dx][dy] = dist[x][y] + 1;
      dfs(dx, dy);
    }
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n >> m;
  mat.resize(n, vector<char>(m));
  dist.resize(n, vector<int>(m));
  visited.resize(n, vector<int>(m));
  for (long long i = 0; i < n; i++) {
    for (long long j = 0; j < m; j++) {
      cin >> mat[i][j];
    }
  }
  for (long long i = 0; i < n; i++) {
    for (long long j = 0; j < m; j++) {
      if (mat[i][j] == '.') {
        dfs(i, j);
        break;
      }
    }
  }
  int maxDist = 0;
  int x = 0, y = 0;
  for (long long i = 0; i < n; i++) {
    for (long long j = 0; j < m; j++) {
      if (maxDist < dist[i][j]) {
        maxDist = dist[i][j];
        x = i;
        y = j;
      }
    }
  }
  for (long long i = 0; i < n; i++) {
    fill(dist[i].begin(), dist[i].end(), 0);
    fill(visited[i].begin(), visited[i].end(), 0);
  }
  dfs(x, y);
  maxDist = 0;
  for (long long i = 0; i < n; i++) {
    for (long long j = 0; j < m; j++) {
      maxDist = max(maxDist, dist[i][j]);
    }
  }
  cout << maxDist;
  return 0;
}
