#include <bits/stdc++.h>
using namespace std;
int H, W;
vector<string> M;
int dx[4] = {-1, 1, 0, 0};
int dy[4] = {0, 0, 1, -1};
int bfs(int x, int y) {
  vector<vector<bool>> visited(30, vector<bool>(30, false));
  queue<pair<pair<int, int>, int>> q;
  q.push(make_pair(make_pair(x, y), 0));
  visited[y][x] = true;
  int cost = 0;
  while (!q.empty()) {
    pair<pair<int, int>, int> p = q.front();
    q.pop();
    for (int k = 0; k < (4); k++) {
      int nx = p.first.first + dx[k];
      int ny = p.first.second + dy[k];
      if (nx < 0 || W <= nx || ny < 0 || H <= ny || M[ny][nx] == '#') continue;
      if (visited[ny][nx]) continue;
      visited[ny][nx] = true;
      pair<pair<int, int>, int> np = make_pair(make_pair(nx, ny), p.second + 1);
      cost = max(cost, p.second + 1);
      q.push(np);
    }
  }
  return cost;
}
int main() {
  cin >> H >> W;
  M.resize(H);
  for (int i = 0; i < (H); i++) cin >> M[i];
  int ans = 0;
  for (int j = 0; j < (H); j++) {
    for (int i = 0; i < (W); i++) {
      ans = max(ans, bfs(i, j));
    }
  }
  cout << ans << endl;
}
