#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
const long double PI = acos(-1);
const long double EPS = 0.0000000001;
int h, w, ans = 0;
vector<vector<bool>> seen;
vector<vector<int>> path;
vector<vector<char>> g;
int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
int main() {
  cin >> h >> w;
  g.resize(h, vector<char>(w));
  for (int i = 0; i < h; i++)
    for (int j = 0; j < w; j++) cin >> g[i][j];
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (g[i][j] == '#') continue;
      seen.assign(h, vector<bool>(w, false));
      path.assign(h, vector<int>(w, 0));
      queue<pair<int, int>> que;
      que.push({i, j});
      while (!que.empty()) {
        int x = que.front().first, y = que.front().second;
        que.pop();
        for (int i = 0; i < 4; i++) {
          int nx = x + dx[i], ny = y + dy[i];
          if (nx < 0 || ny < 0 || h <= nx || w <= ny) continue;
          if (g[nx][ny] == '#' || 0 < path[nx][ny]) continue;
          path[nx][ny] = path[x][y] + 1;
          que.push({nx, ny});
        }
      }
      for (int k = 0; k < h; k++) {
        for (int l = 0; l < w; l++) {
          if (g[k][l] == '#') continue;
          ans = max(ans, path[k][l]);
        }
      }
    }
  }
  cout << ans << endl;
}
