#include <bits/stdc++.h>
using namespace std;
int h, w;
char maze[30][30];
int bfs(int sx, int sy, int gx, int gy) {
  int dx[] = {-1, 0, 0, 1};
  int dy[] = {0, -1, 1, 0};
  int dist[30][30];
  for (int i = 0; i < (30); ++i)
    for (int j = 0; j < (30); ++j) dist[i][j] = -1;
  queue<pair<int, int> > que;
  que.push(make_pair(sx, sy));
  dist[sy][sx] = 0;
  while (!que.empty()) {
    auto x = que.front().first;
    auto y = que.front().second;
    que.pop();
    for (int i = 0; i < (4); ++i) {
      int nx = x + dx[i];
      int ny = y + dy[i];
      if (nx < 0 || nx >= w || ny < 0 || ny >= h) {
        continue;
      }
      if (maze[ny][nx] == '#') {
        continue;
      }
      if (dist[ny][nx] != -1) {
        continue;
      }
      dist[ny][nx] = dist[y][x] + 1;
      que.push(make_pair(nx, ny));
    }
  }
  return dist[gy][gx];
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << setprecision(20) << fixed;
  cin >> h >> w;
  for (int i = 0; i < (h); ++i) {
    cin >> maze[i];
  }
  int ans = 0;
  for (int sx = 0; sx < (w); ++sx) {
    for (int sy = 0; sy < (h); ++sy) {
      for (int gx = 0; gx < (w); ++gx) {
        for (int gy = 0; gy < (h); ++gy) {
          if (maze[sy][sx] == '.' && maze[gy][sx] == '.') {
            int t = bfs(sx, sy, gx, gy);
            ans = max(ans, t);
          }
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}
