#include <bits/stdc++.h>
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
using namespace std;
bool inside(int x, int y, int w, int h) {
  return (x >= 0 && y >= 0 && x < w && y < h);
}
int dx[] = {1, 0, -1, 0};
int dy[] = {0, -1, 0, 1};
int w, h;
string mas[25];
int dist[30][30];
int main() {
  cin.tie(0);
  ios::sync_with_stdio(0);
  int maxv = 0, sx, sy;
  cin >> w >> h;
  for (int i = 0; i < w; i++) {
    cin >> mas[i];
    for (int j = 0; j < h; j++) {
      if (mas[i][j] == '.') {
        sy = j;
        sx = i;
      }
    }
  }
  for (int i = 0; i < w; i++) {
    for (int j = 0; j < h; j++) {
      dist[i][j] = INF;
    }
  }
  queue<pair<int, int> > que;
  dist[sx][sy] = 0;
  que.push(make_pair(sx, sy));
  while (!que.empty()) {
    int x = que.front().first;
    int y = que.front().second;
    que.pop();
    for (int z = 0; z < 4; z++) {
      int nx = x + dx[z];
      int ny = y + dy[z];
      if (inside(nx, ny, w, h) && dist[nx][ny] > dist[x][y] + 1 &&
          mas[nx][ny] != '#') {
        dist[nx][ny] = dist[x][y] + 1;
        que.push(make_pair(nx, ny));
      }
    }
  }
  for (int i = 0; i < (w); i++) {
    for (int j = 0; j < (h); j++) {
      if (dist[i][j] != INF && maxv < dist[i][j]) {
        maxv = dist[i][j];
        sx = i;
        sy = j;
      }
    }
  }
  for (int i = 0; i < w; i++) {
    for (int j = 0; j < h; j++) {
      dist[i][j] = INF;
    }
  }
  dist[sx][sy] = 0;
  que.push(make_pair(sx, sy));
  while (!que.empty()) {
    int x = que.front().first;
    int y = que.front().second;
    que.pop();
    for (int z = 0; z < 4; z++) {
      int nx = x + dx[z];
      int ny = y + dy[z];
      if (inside(nx, ny, w, h) && dist[nx][ny] > dist[x][y] + 1 &&
          mas[nx][ny] != '#') {
        dist[nx][ny] = dist[x][y] + 1;
        que.push(make_pair(nx, ny));
      }
    }
  }
  for (int i = 0; i < (w); i++) {
    for (int j = 0; j < (h); j++) {
      if (dist[i][j] != INF) maxv = max(maxv, dist[i][j]);
    }
  }
  cout << maxv << '\n';
  return 0;
}
