#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int MAX = 20;
int h, w;
char s[MAX + 1][MAX + 1];
int d[MAX + 1][MAX + 1];
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
queue<pair<int, int>> que;
void bfs(int x, int y) {
  while (!que.empty()) {
    pair<int, int> p = que.front();
    que.pop();
    x = p.first;
    y = p.second;
    for (int i = (0); i < (4); ++i) {
      int nx = x + dx[i];
      int ny = y + dy[i];
      if (nx < 0 || w <= nx || ny < 0 || h <= ny) continue;
      if (s[nx][ny] == '.' && d[nx][ny] == -1) {
        d[nx][ny] = d[x][y] + 1;
        que.push(make_pair(nx, ny));
      }
    }
  }
}
int main() {
  cin >> h >> w;
  for (int i = (0); i < (h); ++i)
    for (int j = (0); j < (w); ++j) cin >> s[j][i];
  int ans = 0;
  for (int sy = (0); sy < (h); ++sy) {
    for (int sx = (0); sx < (w); ++sx) {
      que.push(make_pair(sx, sy));
      for (int i = (0); i < (h); ++i)
        for (int j = (0); j < (w); ++j) d[j][i] = -1;
      d[sx][sy] = 0;
      bfs(sx, sy);
      for (int i = (0); i < (h); ++i)
        for (int j = (0); j < (w); ++j) ans = max(ans, d[j][i]);
    }
  }
  cout << ans << endl;
  return 0;
}
