#include <bits/stdc++.h>
using namespace std;
const int N = 25;
int n, m;
char a[N][N];
int d[N][N];
bool used[N][N];
int posx[] = {1, -1, 0, 0};
int posy[] = {0, 0, 1, -1};
bool valid(int x, int y) { return (x >= 1 && x <= n && y >= 1 && y <= m); }
void bfs(int x, int y) {
  queue<pair<int, int>> q;
  q.push({x, y});
  d[x][y] = 0;
  used[x][y] = true;
  while (!q.empty()) {
    pair<int, int> p = q.front();
    int px = p.first;
    int py = p.second;
    q.pop();
    for (int i = 0; i < 4; i++) {
      int tox = px + posx[i];
      int toy = py + posy[i];
      if (valid(tox, toy) && a[tox][toy] == '.' && !used[tox][toy]) {
        d[tox][toy] = d[px][py] + 1;
        used[tox][toy] = true;
        q.push({tox, toy});
      }
    }
  }
}
void init() {
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      d[i][j] = 0;
      used[i][j] = false;
    }
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      cin >> a[i][j];
    }
  }
  int ans = 0;
  for (int x1 = 1; x1 <= n; x1++) {
    for (int y1 = 1; y1 <= m; y1++) {
      if (d[x1][y1] == '#') {
        continue;
      }
      init();
      bfs(x1, y1);
      for (int x2 = 1; x2 <= n; x2++) {
        for (int y2 = 1; y2 <= m; y2++) {
          ans = max(ans, d[x2][y2]);
        }
      }
    }
  }
  cout << ans << '\n';
  return 0;
}
