#include <bits/stdc++.h>
using namespace std;
const int dr[] = {0, 0, 1, -1};
const int dc[] = {1, -1, 0, 0};
char a[30][30];
int visited[30][30];
int dist[30][30];
int bfs(int x, int y, int n, int m) {
  memset(visited, 0, sizeof(visited));
  visited[x][y] = 1;
  queue<pair<int, int> > q;
  q.push({x, y});
  dist[x][y] = 0;
  int mx = 0;
  while (!q.empty()) {
    pair<int, int> fr;
    fr = q.front();
    q.pop();
    int x = fr.first;
    int y = fr.second;
    int nx, ny;
    for (int i = 0; i < 4; i++) {
      nx = x + dr[i];
      ny = y + dc[i];
      if (nx > n || ny > m || nx < 1 || ny < 1 || a[nx][ny] == '#') continue;
      if (!visited[nx][ny]) {
        q.push({nx, ny});
        dist[nx][ny] = dist[x][y] + 1;
        visited[nx][ny] = 1;
        mx = max(mx, dist[nx][ny]);
      }
    }
  }
  return mx;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int rows, cols;
  cin >> rows >> cols;
  for (int i = 1; i <= rows; i++) {
    for (int j = 1; j <= cols; j++) {
      cin >> a[i][j];
    }
  }
  int ans = 0;
  for (int i = 1; i <= rows; i++) {
    for (int j = 1; j <= cols; j++) {
      if (a[i][j] == '.') ans = max(ans, bfs(i, j, rows, cols));
    }
  }
  cout << ans << endl;
  return 0;
}
