#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int dx[] = {1, 0, -1, 0};
int dy[] = {0, -1, 0, 1};
int main() {
  int H, W;
  cin >> H >> W;
  vector<string> field;
  for (int i = 0; i < H; i++) {
    string s;
    cin >> s;
    field.push_back(s);
  }
  auto calc = [&](int x, int y) {
    vector<vector<int>> dist(H, vector<int>(W, 1e9));
    queue<pair<int, pair<int, int>>> que;
    que.push(make_pair(0, make_pair(x, y)));
    while (!que.empty()) {
      auto q = que.front();
      que.pop();
      if (dist[q.second.first][q.second.second] != 1e9) {
        continue;
      }
      dist[q.second.first][q.second.second] = q.first;
      for (int i = 0; i < 4; i++) {
        if (0 <= q.second.first + dx[i] && q.second.first + dx[i] < H &&
            0 <= q.second.second + dy[i] && q.second.second + dy[i] < W) {
          if (field[q.second.first + dx[i]][q.second.second + dy[i]] != '#') {
            que.push(make_pair(
                q.first + 1,
                make_pair(q.second.first + dx[i], q.second.second + dy[i])));
          }
        }
      }
    }
    int ans = 0;
    for (int i = 0; i < H; i++) {
      for (int j = 0; j < W; j++) {
        if (field[i][j] == '.') {
          ans = max(dist[i][j], ans);
        }
      }
    }
    return ans;
  };
  int ans = 0;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      ans = max(calc(i, j), ans);
    }
  }
  cout << ans << endl;
  return 0;
}
