#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1e18;
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
int dy[4] = {-1, 0, 1, 0}, dx[4] = {0, 1, 0, -1};
int h, w;
vector<string> s(h);
int bfs(int sy, int sx) {
  queue<pair<int, int>> q;
  vector<vector<int>> dist(h, vector<int>(w, -1));
  dist[sy][sx] = 0;
  q.push(pair<int, int>(sy, sx));
  while (!q.empty()) {
    pair<int, int> now = q.front();
    q.pop();
    int y = now.first, x = now.second;
    for (int i = 0; i < (4); i++) {
      int ny = y + dy[i], nx = x + dx[i];
      if (ny < 0 || ny >= h || nx < 0 || nx >= w) continue;
      if (s[ny][nx] == '#') continue;
      if (dist[ny][nx] == -1) {
        q.push(pair<int, int>(ny, nx));
        dist[ny][nx] = dist[y][x] + 1;
      }
    }
  }
  int ret = 0;
  for (int i = 0; i < (h); i++)
    for (int j = 0; j < (w); j++) ret = max(ret, dist[i][j]);
  return ret;
}
int main(int argc, char const* argv[]) {
  int ans = 0;
  cin >> h >> w;
  for (int i = 0; i < (h); i++) cin >> s[i];
  for (int i = 0; i < (h); i++)
    for (int j = 0; j < (w); j++) {
      if (s[i][j] == '#') continue;
      int res = bfs(i, j);
      ans = max(ans, res);
    }
  cout << ans << endl;
  return 0;
}
