#include <bits/stdc++.h>
using namespace std;
int h, w;
int max(string s[], int x, int y) {
  queue<int> q;
  int max = -1;
  int dist[405];
  for (int i = 0; i < h * w; i++) {
    dist[i] = -1;
  }
  dist[y * w + x] = 0;
  if (x > 0) {
    if (s[y][x - 1] == '.') {
      q.push(x - 1 + y * w);
      dist[x - 1 + y * w] = dist[y * w + x] + 1;
    }
  }
  if (x < w - 1) {
    if (s[y][x + 1] == '.') {
      q.push(x + 1 + y * w);
      dist[x + 1 + y * w] = dist[y * w + x] + 1;
    }
  }
  if (y > 0) {
    if (s[y - 1][x] == '.') {
      q.push(x + (y - 1) * w);
      dist[x + (y - 1) * w] = dist[y * w + x] + 1;
    }
  }
  if (y < h - 1) {
    if (s[y + 1][x] == '.') {
      q.push(x + (y + 1) * w);
      dist[x + (y + 1) * w] = dist[y * w + x] + 1;
    }
  }
  while (!q.empty()) {
    int p = q.front();
    q.pop();
    if (p % w > 0) {
      if (s[p / w][p % w - 1] == '.' && dist[p - 1] == -1) {
        q.push(p - 1);
        dist[p - 1] = dist[p] + 1;
      }
    }
    if (p % w < w - 1) {
      if (s[p / w][p % w + 1] == '.' && dist[p + 1] == -1) {
        q.push(p + 1);
        dist[p + 1] = dist[p] + 1;
      }
    }
    if (p / w > 0) {
      if (s[p / w - 1][p % w] == '.' && dist[p - w] == -1) {
        q.push(p - w);
        dist[p - w] = dist[p] + 1;
      }
    }
    if (p / w < h - 1) {
      if (s[p / w + 1][p % w] == '.' && dist[p + w] == -1) {
        q.push(p + w);
        dist[p + w] = dist[p] + 1;
      }
    }
  }
  for (int i = 0; i < h * w; i++) {
    if (max < dist[i]) max = dist[i];
  }
  return max;
}
int main() {
  int ans = -1;
  string s[20];
  cin >> h >> w;
  for (int i = 0; i < h; i++) {
    cin >> s[i];
  }
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      int t = max(s, j, i);
      if (ans < t) ans = t;
    }
  }
  cout << ans << endl;
  return 0;
}
