#include <bits/stdc++.h>
using namespace std;
const int INF = 1000000;
int h, w;
char field[25][25];
int d[25][25];
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
int ans;
void bfs(int y, int x) {
  queue<pair<int, int> > que;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      d[i][j] = INF;
    }
  }
  que.push(pair<int, int>(x, y));
  d[y][x] = 0;
  while (que.size()) {
    pair<int, int> p = que.front();
    que.pop();
    for (int i = 0; i < 4; i++) {
      int nx = p.first + dx[i], ny = p.second + dy[i];
      if (nx < 0 || w <= nx || ny < 0 || h <= ny) continue;
      if (field[ny][nx] == '#') continue;
      if (d[ny][nx] != INF) continue;
      que.push(pair<int, int>(nx, ny));
      d[ny][nx] = d[p.second][p.first] + 1;
      ans = max(d[ny][nx], ans);
    }
  }
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> h >> w;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      cin >> field[i][j];
    }
  }
  ans = 0;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      bfs(i, j);
    }
  }
  cout << ans << endl;
  return 0;
}
