#include <bits/stdc++.h>
using namespace std;
int dx[4] = {0, 0, -1, 1};
int dy[4] = {-1, 1, 0, 0};
bool IA(int x, int y, int xl, int yl) {
  return (x >= 0 && x < xl && y >= 0 && y < yl);
}
int h, w, ans = 0;
char s[22][22];
int main() {
  cin >> h >> w;
  for (int i = 0; i < h; i++)
    for (int j = 0; j < w; j++) cin >> s[i][j];
  for (int i = 0; i < h; i++)
    for (int j = 0; j < w; j++) {
      if (s[i][j] == '#') continue;
      int dist[22][22] = {}, mx = 0;
      for (int i = 0; i < h; i++)
        for (int j = 0; j < w; j++) dist[i][j] = 12345;
      dist[i][j] = 0;
      queue<pair<pair<int, int>, int>> q;
      q.push({{i, j}, 0});
      while (!q.empty()) {
        auto tp = q.front();
        q.pop();
        int x = tp.first.first;
        int y = tp.first.second;
        for (int d = 0; d < 4; d++) {
          int nx = x + dx[d];
          int ny = y + dy[d];
          if (IA(nx, ny, h, w) && s[nx][ny] == '.' &&
              dist[nx][ny] > dist[x][y]) {
            q.push({{nx, ny}, dist[x][y] + 1});
            dist[nx][ny] = dist[x][y] + 1;
            mx = max(mx, dist[nx][ny]);
          }
        }
      }
      ans = max(ans, mx);
    }
  cout << ans << endl;
  return 0;
}
