#include <bits/stdc++.h>
using lint = long long;
using namespace std;
const int MOD = 1000000007;
const int INF = 1 << 14;
int H, W;
string S[30];
int bfs(int y, int x) {
  queue<pair<int, int> > q;
  q.push(pair<int, int>(y, x));
  int d[30][30];
  for (int i = 0; i < (int)(H); i++) {
    for (int j = 0; j < (int)(W); j++) {
      d[i][j] = INF;
    }
  }
  d[y][x] = 0;
  while (q.size()) {
    pair<int, int> p = q.front();
    q.pop();
    int i = p.first;
    int j = p.second;
    if (i > 0 && S[i - 1][j] == '.') {
      if (d[i - 1][j] == INF || d[i - 1][j] > d[i][j] + 1) {
        q.push(pair<int, int>(i - 1, j));
        d[i - 1][j] = d[i][j] + 1;
      }
    }
    if (i < H - 1 && S[i + 1][j] == '.' &&
        (d[i + 1][j] == INF || d[i + 1][j] > d[i][j] + 1)) {
      q.push(pair<int, int>(i + 1, j));
      d[i + 1][j] = d[i][j] + 1;
    }
    if (i > 0 && S[i][j - 1] == '.' &&
        (d[i][j - 1] == INF || d[i][j - 1] > d[i][j] + 1)) {
      q.push(pair<int, int>(i, j - 1));
      d[i][j - 1] = d[i][j] + 1;
    }
    if (j < W - 1 && S[i][j + 1] == '.' &&
        (d[i][j + 1] == INF || d[i][j + 1] > d[i][j] + 1)) {
      q.push(pair<int, int>(i, j + 1));
      d[i][j + 1] = d[i][j] + 1;
    }
  }
  int m = 0;
  for (int i = 0; i < (int)(H); i++) {
    for (int j = 0; j < (int)(W); j++) {
      if (d[i][j] != INF) m = max(m, d[i][j]);
    }
  }
  return m;
}
int main() {
  cin >> H >> W;
  for (int i = 0; i < (int)(H); i++) cin >> S[i];
  int res = 0;
  for (int i = 0; i < (int)(H); i++) {
    for (int j = 0; j < (int)(W); j++) {
      if (S[i][j] == '.') {
        res = max(res, bfs(i, j));
      }
    }
  }
  cout << res << endl;
  return 0;
}
