#include <bits/stdc++.h>
using namespace std;
char maze[100][100];
int dist[100][100];
int main() {
  int H, W;
  cin >> H >> W;
  int sy, sx, gy, gx;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      cin >> maze[i][j];
    }
  }
  int dx[4] = {0, 0, 1, -1};
  int dy[4] = {1, -1, 0, 0};
  int ans = 0;
  for (int sy = 0; sy < H; sy++) {
    for (int sx = 0; sx < W; sx++) {
      for (int gy = 0; gy < H; gy++) {
        for (int gx = 0; gx < W; gx++) {
          if (maze[sy][sx] != '.' || maze[gy][gx] != '.') break;
          for (int i = 0; i < H; i++) {
            for (int j = 0; j < W; j++) {
              dist[i][j] = -99999999;
            }
          }
          queue<pair<int, int>> que;
          while (!que.empty()) {
            que.pop();
          }
          que.push(make_pair(sx, sy));
          dist[sy][sx] = 0;
          while (!que.empty()) {
            pair<int, int> p = que.front();
            que.pop();
            int x = p.first;
            int y = p.second;
            if (x == gx && y == gy) break;
            for (int i = 0; i < 4; i++) {
              int mx = x + dx[i];
              int my = y + dy[i];
              if (mx < 0 || my < 0 || mx >= W || my >= H) continue;
              if (maze[my][mx] != '#' && dist[my][mx] == -99999999) {
                que.push(make_pair(mx, my));
                dist[my][mx] = dist[y][x] + 1;
              }
            }
          }
          ans = max(ans, dist[gy][gx]);
        }
      }
    }
  }
  cout << ans << endl;
}
