#include <bits/stdc++.h>
using namespace std;
char S[22][22];
int check[22][22];
int dx[4] = {-1, 0, 1, 0};
int dy[4] = {0, -1, 0, 1};
int H, W;
void disp() {
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      printf("%3d ", check[i][j]);
    }
    printf("\n");
  }
}
int rec(int x, int y) {
  int nx, ny;
  int m = 0;
  int cnt = 0;
  int np;
  int step = 0;
  check[y][x] = 0;
  do {
    np = 0;
    for (int y1 = 0; y1 < H; y1++) {
      for (int x1 = 0; x1 < W; x1++) {
        if (check[y1][x1] == step) {
          for (int i = 0; i < 4; i++) {
            nx = x1 + dx[i];
            ny = y1 + dy[i];
            if (nx >= 0 && nx < W && ny >= 0 && ny < H) {
              if (check[ny][nx] == -1 && S[ny][nx] == '.') {
                check[ny][nx] = step + 1;
                np = 1;
              }
            }
          }
        }
      }
    }
    if (np == 1) step++;
  } while (np == 1);
  return step;
}
int main(void) {
  int ms = 0;
  cin >> H >> W;
  for (int i = 0; i < H; i++) {
    cin >> S[i];
  }
  for (int y = 0; y < H; y++)
    for (int x = 0; x < W; x++) {
      for (int i = 0; i < H; i++)
        for (int j = 0; j < W; j++) check[i][j] = -1;
      ms = max(rec(x, y), ms);
    }
  cout << ms << endl;
}
