#include <bits/stdc++.h>
using namespace std;
int h = 0, w = 0;
char arr[21][21];
int d[401][401];
int di[4] = {1, -1, 0, 0};
int dj[4] = {0, 0, 1, -1};
int cd(int i, int j) { return i * h + j; }
bool check(int i, int j) {
  return (i >= 0 && i < h && j >= 0 && j < w && arr[i][j] == '.');
}
int main() {
  cin >> h >> w;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      cin >> arr[i][j];
    }
  }
  for (int i = 0; i < h * w; i++) {
    for (int j = 0; j < h * w; j++) d[i][j] = 1000000;
  }
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (arr[i][j] == '.')
        for (int k = 0; k < 4; k++) {
          if (check(i + di[k], j + dj[k]))
            d[cd(i, j)][cd(i + di[k], j + dj[k])] = 1;
        }
    }
  }
  for (int k = 0; k < h * w; k++) {
    for (int i = 0; i < h * w; i++) {
      for (int j = 0; j < h * w; j++) {
        d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
      }
    }
  }
  int Max = 0;
  for (int i = 0; i < h * w; i++)
    for (int j = 0; j < h * w; j++)
      if (d[i][j] != 1000000) Max = max(Max, d[i][j]);
  cout << Max;
  return 0;
}
