#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
int x_1, y_1, H, W, s_x, s_y, g_y, g_x, sum1;
char S[20][20];
struct Object {
  int x;
  int y;
  int sum;
};
const int yvec[4] = {0, 0, -1, 1};
const int xvec[4] = {-1, 1, 0, 0};
bool hantei[20][20];
int bfs(Object st) {
  queue<Object> q;
  q.push(st);
  sum1 = 0;
  while (!q.empty()) {
    Object now = q.front();
    q.pop();
    x_1 = now.x;
    y_1 = now.y;
    sum1 = now.sum;
    for (int i = 0; i < H; i++) {
      for (int j = 0; j < W; j++) {
        hantei[i][j] = false;
      }
    }
    for (int i = 0; i < 4; i++) {
      Object next = {x_1 + xvec[i], y_1 + yvec[i], sum1 + 1};
      if (0 <= next.y && next.y <= H - 1 && 0 <= next.x && next.y <= W - 1 &&
          S[next.y][next.x] == '.' && hantei[next.y][next.x] == false) {
        hantei[next.y][next.x] = true;
        q.push(next);
      }
    }
  }
  return sum1;
}
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] == '.') {
        Object start = {i, j, 0};
        ans = max(ans, bfs(start));
      }
    }
  }
  cout << ans << endl;
  return 0;
}
