#include <bits/stdc++.h>
using namespace std;
const vector<int> dx = {1, -1, 0, 0}, dy = {0, 0, 1, -1};
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int H, W;
  cin >> H >> W;
  vector<string> S(H);
  for (int i = 0; i < H; i++) {
    cin >> S[i];
  }
  int res = 0;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      vector<vector<int>> graph(H, vector<int>(W, -1));
      graph[i][j] = 0;
      queue<pair<int, int>> que;
      que.push(make_pair(i, j));
      while (!que.empty()) {
        auto q = que.front();
        que.pop();
        int y = q.first, x = q.second;
        for (int k = 0; k < 4; k++) {
          int ny = y + dy[k], nx = x + dx[k];
          if (ny < 0 || ny >= H || nx < 0 || nx >= W) continue;
          if (S[ny][nx] == '#' || graph[ny][nx] != -1) continue;
          graph[ny][nx] = graph[y][x] + 1;
          que.push(make_pair(ny, nx));
        }
      }
      int maxn = 0;
      for (int y = 0; y < H; y++) {
        for (int x = 0; x < W; x++) {
          maxn = max(maxn, graph[y][x]);
        }
      }
      res = max(res, maxn);
    }
  }
  cout << res << '\n';
  return 0;
}
