#include <bits/stdc++.h>
using namespace std;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
int bfs(const vector<string> &v, int x, int y) {
  int res = 0;
  int H = v.size(), W = v[0].size();
  queue<pair<int, int>> q;
  q.push({x, y});
  vector<vector<int>> dist(H, vector<int>(W, -1));
  dist[x][y] = 0;
  while (!q.empty()) {
    int X = q.front().first, Y = q.front().second;
    int nowDist = dist[X][Y];
    res = max(res, nowDist);
    q.pop();
    for (int i = 0; i < 4; ++i) {
      int nx = X + dx[i], ny = Y + dy[i];
      if (nx < 0 || nx >= H || ny < 0 || ny >= W) continue;
      if (v[nx][ny] == '#') continue;
      if (dist[nx][ny] == -1) {
        dist[nx][ny] = nowDist + 1;
        q.push({nx, ny});
      }
    }
  }
  return res;
}
int main() {
  int h, w, ans = 0;
  cin >> h >> w;
  vector<string> v(h);
  for (int i = 0; i < h; ++i) {
    cin >> v[i];
  }
  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j) {
      ans = max(ans, bfs(v, i, j));
    }
  }
  cout << ans << '\n';
  return 0;
}
