#include <bits/stdc++.h>
using namespace std;
const long long M = 6e5, MOD = 2e9;
char ch[100][100];
int m, n;
int mx = 0;
int x2, y2;
struct Node {
  int x, y;
};
queue<Node> q;
bool vis[100][100];
int A[] = {1, -1, 0, 0};
int B[] = {0, 0, 1, -1};
int dist[100][100];
void bfs(int x1, int yy) {
  q.push({x1, yy});
  dist[x1][yy] = 0;
  vis[x1][yy] = 1;
  while (q.size()) {
    int a = q.front().x;
    int b = q.front().y;
    q.pop();
    for (int i = 0; i < 4; i++) {
      int x3 = a + A[i];
      int y3 = b + B[i];
      if (x3 >= 0 && x3 < m && y3 >= 0 && y3 < n && ch[x3][y3] == '.') {
        if (!vis[x3][y3]) {
          dist[x3][y3] = dist[a][b] + 1;
          mx = max(mx, dist[x3][y3]);
          vis[x3][y3] = 1;
          q.push({x3, y3});
        } else {
          dist[x3][y3] = min(dist[x3][y3], dist[a][b] + 1);
          mx = max(mx, dist[x3][y3]);
        }
      }
    }
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> m >> n;
  for (int i = 0; i < m; i++)
    for (int j = 0; j < n; j++) cin >> ch[i][j];
  for (int i = 0; i < m; i++) {
    for (int j = 0; j < n; j++) {
      if (ch[i][j] == '.') {
        bfs(i, j);
      }
    }
    for (int k = 0; k < m; k++) {
      for (int l = 0; l < n; l++) dist[k][l] = vis[k][l] = 0;
    }
  }
  cout << mx << endl;
  return 0;
}
