#include <bits/stdc++.h>
using namespace std;
int main() {
  int h, w, v;
  cin >> h >> w;
  v = h * w;
  vector<vector<char>> c(h, vector<char>(w));
  vector<vector<int>> G(v, vector<int>(v, 1e8));
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      cin >> c[i][j];
    }
  }
  for (int i = 0; i < v; i++) {
    bool is_wall = c[i / w][i % w] == '#';
    for (int j = 0; j < v; j++) {
      if (i == j)
        G[i][j] = 0;
      else if (is_wall) {
        G[i][j] = 1e8;
      } else if ((abs(i / w - j / w) == 1 && i % w == j % w) ||
                 (abs(i % w - j % w) == 1 && i / w == j / w)) {
        if (c[i / w][i % w] == '#')
          G[i][j] = 1e8;
        else
          G[i][j] = 1;
      } else {
        G[i][j] = 1e8;
      }
    }
  }
  for (int k = 0; k < v; k++) {
    for (int i = 0; i < v; i++) {
      for (int j = 0; j < v; j++) {
        G[i][j] = min(G[i][j], G[i][k] + G[k][j]);
      }
    }
  }
  int ans = 0;
  for (int i = 0; i < v; i++) {
    for (int j = 0; j < v; j++) {
      if (G[i][j] != 1e8) ans = max(ans, G[i][j]);
    }
  }
  cout << ans << endl;
}
