#include <bits/stdc++.h>
using namespace std;
int H, W;
struct st {
  int y, x;
} imsi;
queue<st> q;
string jido[25];
int cango[25][25];
int dis[25][25];
int vst[25][25];
int my[4] = {-1, 0, 1, 0}, mx[4] = {0, 1, 0, -1};
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> H >> W;
  for (int i = 0; i < H; i++) {
    cin >> jido[i];
    for (int j = 1; j <= W; j++) {
      if (jido[i][j - 1] == '.')
        cango[i + 1][j] = 1, imsi.y = i + 1, imsi.x = j;
    }
  }
  q.push({imsi});
  while (!q.empty()) {
    st now = q.front();
    q.pop();
    vst[now.y][now.x] = 1;
    for (int i = 0; i < 4; i++) {
      int ny = now.y + my[i], nx = now.x + mx[i];
      if (!vst[ny][nx] && cango[ny][nx]) {
        vst[ny][nx] = 1;
        q.push({ny, nx});
        dis[ny][nx] = dis[now.y][now.x] + 1;
      }
    }
  }
  int m = -1;
  for (int i = 1; i <= H; i++) {
    for (int j = 1; j <= W; j++) {
      if (dis[i][j] > m && cango[i][j]) {
        m = dis[i][j];
        imsi.y = i;
        imsi.x = j;
      }
      dis[i][j] = 0;
      vst[i][j] = 0;
    }
  }
  q.push({imsi});
  while (!q.empty()) {
    st now = q.front();
    q.pop();
    vst[now.y][now.x] = 1;
    for (int i = 0; i < 4; i++) {
      int ny = now.y + my[i], nx = now.x + mx[i];
      if (!vst[ny][nx] && cango[ny][nx]) {
        vst[ny][nx] = 1;
        q.push({ny, nx});
        dis[ny][nx] = dis[now.y][now.x] + 1;
      }
    }
  }
  m = -1;
  for (int i = 1; i <= H; i++) {
    for (int j = 1; j <= W; j++) {
      if (dis[i][j] > m && cango[i][j]) {
        m = dis[i][j];
        imsi.y = i;
        imsi.x = j;
      }
    }
  }
  cout << m;
}
