#include <bits/stdc++.h>
using namespace std;
char m[23][23];
int dist[23][23], processado[23][23];
int iv = 0, jv = 0, av = 0, l, c;
int x[] = {1, -1, 0, 0};
int y[] = {0, 0, 1, -1};
priority_queue<pair<int, pair<int, int> >, vector<pair<int, pair<int, int> > >,
               greater<pair<int, pair<int, int> > > >
    fila;
void solve(int i, int j, int tam) {
  dist[i][j] = tam;
  for (int z = 0; z < 4; z++) {
    if (i + x[z] >= 0 && i + x[z] < l && j + y[z] >= 0 && j + y[z] < c &&
        m[i + x[z]][j + y[z]] == '.') {
      pair<int, pair<int, int> > xd;
      xd.first = tam + 1;
      xd.second = pair<int, int>(i + x[z], j + y[z]);
      fila.push(xd);
    }
  }
  while (!fila.empty()) {
    if (processado[fila.top().second.first][fila.top().second.second] == 1) {
      fila.pop();
      continue;
    }
    if (fila.top().first > av) av = fila.top().first;
    processado[fila.top().second.first][fila.top().second.second] = 1;
    solve(fila.top().second.first, fila.top().second.second, fila.top().first);
  }
  return;
}
int main() {
  cin >> l >> c;
  for (int i = 0; i < l; i++)
    for (int j = 0; j < c; j++) cin >> m[i][j];
  for (int i = 0; i < l; i++)
    for (int j = 0; j < c; j++) {
      memset(dist, 0, sizeof dist);
      memset(processado, 0, sizeof processado);
      if (m[i][j] == '.') solve(i, j, 0);
    }
  cout << av << endl;
}
