#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int dx[4] = {0, 0, 1, -1};
int dy[4] = {1, -1, 0, 0};
ll BFS(int rx, int ry, vector<string> &area) {
  int H, W;
  H = area.size();
  W = area[0].size();
  queue<pair<int, int>> q;
  queue<ll> c;
  vector<vector<int>> visited(H, vector<int>(W, 0));
  visited[rx][ry] = 1;
  q.push(make_pair(rx, ry));
  c.push(0);
  ll res = 0;
  while (!q.empty()) {
    pair<int, int> temp = q.front();
    ll cost = c.front();
    q.pop();
    c.pop();
    res = cost;
    for (int i = 0; i < 4; ++i) {
      ll nx = temp.first + dx[i];
      ll ny = temp.second + dy[i];
      ll nc = cost + 1;
      if ((nx < 0 or H <= nx) or (ny < 0 or W <= ny)) {
        continue;
      }
      if (area[nx][ny] == '#') {
        continue;
      }
      if (visited[nx][ny] == 1) {
        continue;
      }
      visited[nx][ny] = 1;
      q.push(make_pair(nx, ny));
      c.push(nc);
    }
  }
  return res;
}
int main() {
  int H, W;
  cin >> H >> W;
  vector<string> area(H);
  for (auto &&e : area) {
    cin >> e;
  }
  ll res = 0;
  for (int i = 0; i < H; ++i) {
    for (int j = 0; j < W; ++j) {
      res = max(res, BFS(i, j, area));
    }
  }
  cout << res << endl;
}
