#include <bits/stdc++.h>
using namespace std;
int H, W;
char S[20][20];
char T[20][20];
int a[20][20];
struct Corr {
  int y;
  int x;
  int depth;
};
int bfs(int s_y, int s_x) {
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      a[i][j] = 0;
    }
  }
  int y_vec[4];
  y_vec[0] = 0;
  y_vec[1] = 0;
  y_vec[2] = -1;
  y_vec[3] = 1;
  int x_vec[4];
  x_vec[0] = -1;
  x_vec[1] = 1;
  x_vec[2] = 0;
  x_vec[3] = 0;
  queue<Corr> q;
  Corr start = {s_y, s_x, 0};
  q.push(start);
  while (!q.empty()) {
    Corr now = q.front();
    q.pop();
    int y = now.y;
    int x = now.x;
    int depth = now.depth;
    for (int i = 0; i < 4; i++) {
      Corr next = {y + y_vec[i], x + x_vec[i], depth + 1};
      if (0 <= next.y && next.y < H && 0 <= next.x && next.x < W &&
          S[next.y][next.x] == '.' && a[next.y][next.x] == 0) {
        a[next.y][next.x] = a[now.y][now.x] + 1;
        q.push(next);
      }
    }
  }
  int m = 0;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      m = max(m, a[i][j]);
    }
  }
  return m;
}
int main() {
  cin >> H >> W;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      cin >> S[i][j];
    }
  }
  int ans = 0;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      if (S[i][j] == '.') ans = max(ans, bfs(i, j));
    }
  }
  cout << ans << endl;
}
