#include <bits/stdc++.h>
using namespace std;
int H, W;
int MAX = 0;
char S[20][20];
queue<pair<int, int> > q;
int dist(pair<int, int> p) {
  q.push(p);
  int Max = 0;
  int maze[20][20] = {0};
  bool used[20][20] = {false};
  while (!q.empty()) {
    pair<int, int> tp = q.front();
    int h = tp.first;
    int w = tp.second;
    if (h > 0 && S[h - 1][w] == '.' && !used[h - 1][w]) {
      q.push({h - 1, w});
      maze[h - 1][w] = maze[h][w] + 1;
      Max = max(Max, maze[h - 1][w]);
      used[h - 1][w] = true;
    }
    if (h < H - 1 && S[h + 1][w] == '.' && !used[h + 1][w]) {
      q.push({h + 1, w});
      maze[h + 1][w] = maze[h][w] + 1;
      Max = max(Max, maze[h + 1][w]);
      used[h + 1][w] = true;
    }
    if (w > 0 && S[h][w - 1] == '.' && !used[h][w - 1]) {
      q.push({h, w - 1});
      maze[h][w - 1] = maze[h][w] + 1;
      Max = max(Max, maze[h][w - 1]);
      used[h][w - 1] = true;
    }
    if (w < W - 1 && S[h][w + 1] == '.' && !used[h][w + 1]) {
      q.push({h, w + 1});
      maze[h][w + 1] = maze[h][w] + 1;
      Max = max(Max, maze[h][w + 1]);
      used[h][w + 1] = true;
    }
    q.pop();
  }
  return Max;
}
int main() {
  cin >> H >> W;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) cin >> S[i][j];
  }
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) MAX = max(MAX, dist({i, j}));
  }
  cout << MAX << endl;
  return 0;
}
