#include <bits/stdc++.h>
using namespace std;
const int inf = 1000000007;
const long long mod = 1000000007;
const double PI = 3.14159265358979323846;
int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};
long long gcd(long long a, long long b) {
  if (b == 0)
    return a;
  else
    return gcd(b, a % b);
}
int cans(bool f) {
  if (f)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}
char m[21][21];
int dist[21][21];
int H, W;
int solve(int sy, int sx) {
  if (m[sy][sx] == '#') return 0;
  for (int i = 0; i < (H); i++)
    for (int j = 0; j < (W); j++) dist[i][j] = 0;
  int M = 0;
  queue<pair<int, int> > q;
  q.push(make_pair(sx, sy));
  while (!q.empty()) {
    pair<int, int> p = q.front();
    q.pop();
    int x = p.first;
    int y = p.second;
    for (int i = 0; i < (4); i++) {
      int X = x + dx[i];
      int Y = y + dy[i];
      if (X >= 0 && Y >= 0 && X < W && Y < H && dist[Y][X] == 0 &&
          m[Y][X] == '.') {
        dist[Y][X] = dist[y][x] + 1;
        if (dist[Y][X] > M) M = dist[Y][X];
        q.push(make_pair(X, Y));
      }
    }
  }
  return M;
}
int main() {
  cin >> H >> W;
  for (int i = 0; i < (H); i++) {
    for (int j = 0; j < (W); j++) {
      cin >> m[i][j];
    }
  }
  int ans = 0;
  for (int i = 0; i < (H); i++)
    for (int j = 0; j < (W); j++) {
      ans = max(ans, solve(i, j));
    }
  cout << ans << endl;
  return 0;
}
