#include <bits/stdc++.h>
using namespace std;
string Grid[22];
int Dist[22][22];
int main() {
  int H, W;
  cin >> H >> W;
  for (int i = 0; i < H; i++) cin >> Grid[i];
  queue<int> Q;
  Q.push(0);
  Q.push(0);
  Dist[0][0] = 1;
  while (!Q.empty()) {
    int X = Q.front();
    Q.pop();
    int Y = Q.front();
    Q.pop();
    if (X > 0 && !Dist[X - 1][Y] && Grid[X - 1][Y] == '.') {
      Dist[X - 1][Y] = Dist[X][Y] + 1;
      Q.push(X - 1);
      Q.push(Y);
    }
    if (X < H - 1 && !Dist[X + 1][Y] && Grid[X + 1][Y] == '.') {
      Dist[X + 1][Y] = Dist[X][Y] + 1;
      Q.push(X + 1);
      Q.push(Y);
    }
    if (Y > 0 && !Dist[X][Y - 1] && Grid[X][Y - 1] == '.') {
      Dist[X][Y - 1] = Dist[X][Y] + 1;
      Q.push(X);
      Q.push(Y - 1);
    }
    if (Y < W - 1 && !Dist[X][Y + 1] && Grid[X][Y + 1] == '.') {
      Dist[X][Y + 1] = Dist[X][Y] + 1;
      Q.push(X);
      Q.push(Y + 1);
    }
  }
  int mx = 0, x, y;
  for (int i = 0; i < H; i++)
    for (int j = 0; j < W; j++)
      if (Dist[i][j] > mx) {
        x = i;
        y = j;
        mx = Dist[i][j];
      }
  memset(Dist, 0, sizeof(Dist));
  Dist[x][y] = 1;
  Q.push(x);
  Q.push(y);
  while (!Q.empty()) {
    int X = Q.front();
    Q.pop();
    int Y = Q.front();
    Q.pop();
    if (X > 0 && !Dist[X - 1][Y] && Grid[X - 1][Y] == '.') {
      Dist[X - 1][Y] = Dist[X][Y] + 1;
      Q.push(X - 1);
      Q.push(Y);
    }
    if (X < H - 1 && !Dist[X + 1][Y] && Grid[X + 1][Y] == '.') {
      Dist[X + 1][Y] = Dist[X][Y] + 1;
      Q.push(X + 1);
      Q.push(Y);
    }
    if (Y > 0 && !Dist[X][Y - 1] && Grid[X][Y - 1] == '.') {
      Dist[X][Y - 1] = Dist[X][Y] + 1;
      Q.push(X);
      Q.push(Y - 1);
    }
    if (Y < W - 1 && !Dist[X][Y + 1] && Grid[X][Y + 1] == '.') {
      Dist[X][Y + 1] = Dist[X][Y] + 1;
      Q.push(X);
      Q.push(Y + 1);
    }
  }
  mx = 0;
  for (int i = 0; i < H; i++)
    for (int j = 0; j < W; j++)
      if (Dist[i][j] > mx) mx = Dist[i][j];
  cout << mx - 1 << endl;
  return 0;
}
