#include <bits/stdc++.h>
using namespace std;
long long dx[] = {-1, 0, 0, 1};
long long dy[] = {0, -1, 1, 0};
class DMazeMaster {
 public:
  vector<vector<char>> G;
  long long H, W;
  set<pair<pair<long long, long long>, pair<long long, long long>>> found;
  long long calc(long long sx, long long sy, long long gx, long long gy) {
    if (sx == gx && sy == gy) return 0;
    if (G[sx][sy] == '#' || G[gx][gy] == '#') return 0;
    pair<long long, long long> start = {sx, sy};
    pair<long long, long long> goal = {gx, gy};
    if (start > goal) swap(start, goal);
    if (found.count({start, goal})) return 0;
    found.insert({start, goal});
    queue<pair<pair<long long, long long>, long long>> q;
    set<pair<long long, long long>> used;
    q.push({{sx, sy}, 0});
    long long res = 0;
    while (!q.empty()) {
      auto kv = q.front();
      q.pop();
      pair<long long, long long> pos = kv.first;
      long long d = kv.second;
      if (used.count(pos)) continue;
      used.insert(pos);
      if (pos.first == gx && pos.second == gy) {
        res = d;
        break;
      }
      for (long long i = 0, i_len = (4); i < i_len; ++i) {
        long long nx = pos.first + dx[i];
        long long ny = pos.second + dy[i];
        if (nx < 0 || ny < 0 || nx >= H || ny >= W) continue;
        if (G[nx][ny] == '#') continue;
        if (used.count({nx, ny})) continue;
        q.push({{nx, ny}, d + 1});
      }
    }
    return res;
  }
  void solve(std::istream& cin, std::ostream& cout) {
    cin >> H >> W;
    G = vector<vector<char>>(H, vector<char>(W));
    for (long long i = 0, i_len = (H); i < i_len; ++i)
      for (long long j = 0, j_len = (W); j < j_len; ++j) cin >> G[i][j];
    long long res = 0;
    for (long long si = 0, si_len = (H); si < si_len; ++si) {
      for (long long sj = 0, sj_len = (W); sj < sj_len; ++sj) {
        for (long long gi = 0, gi_len = (H); gi < gi_len; ++gi) {
          for (long long gj = 0, gj_len = (W); gj < gj_len; ++gj) {
            res = max(res, calc(si, sj, gi, gj));
          }
        }
      }
    }
    cout << res << endl;
  }
};
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  std::istream& in(std::cin);
  std::ostream& out(std::cout);
  DMazeMaster solver;
  solver.solve(in, out);
  return 0;
}
