#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using WGraph = vector<vector<pair<int, ll>>>;
template <class T>
bool chmax(T &a, const T &b) {
  if (b > a) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return true;
  }
  return false;
}
constexpr int dx[4] = {-1, 0, 0, 1}, dy[4] = {0, -1, 1, 0};
constexpr int INF = 1e9;
constexpr long long LINF = 1e18;
void solve() {
  int h, w;
  cin >> h >> w;
  vector<string> field(h);
  for (int i = 0; i < h; i++) {
    cin >> field.at(i);
  }
  int ans = -1;
  for (int i = 0; i < h * w; i++) {
    for (int j = 0; j < h * w; j++) {
      int start_x = i % h, start_y = i / h, goal_x = j % h, goal_y = j / h;
      if (field.at(start_x).at(start_y) == '#' ||
          field.at(goal_x).at(goal_y) == '#')
        continue;
      queue<pair<int, int>> que;
      vector<vector<int>> dis(h, vector<int>(w, INF));
      que.push(make_pair(start_x, start_y));
      dis.at(start_x).at(start_y) = 0;
      while (!que.empty()) {
        int curx = que.front().first, cury = que.front().second;
        que.pop();
        for (int i = 0; i < 4; i++) {
          int nextx = curx + dx[i], nexty = cury + dy[i];
          if (nextx < 0 || nextx > h - 1 || nexty < 0 || nexty > w - 1)
            continue;
          if (field.at(nextx).at(nexty) == '.' &&
              dis.at(nextx).at(nexty) > dis.at(curx).at(cury) + 1) {
            dis.at(nextx).at(nexty) = dis.at(curx).at(cury) + 1;
            que.push(make_pair(nextx, nexty));
          }
        }
      }
      chmax(ans, dis.at(goal_x).at(goal_y));
    }
  }
  cout << ans << "\n";
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(20);
  solve();
  return 0;
}
