#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
const int MOD = 1000000007;
const int INF = 1000000001;
const ll LINF = 1000000001000000001LL;
const char EOL = '\n';
void solve();
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << fixed << setprecision(numeric_limits<double>::max_digits10);
  solve();
  return 0;
}
void solve() {
  int h, w;
  cin >> h >> w;
  vector<string> s(h + 2);
  s[0] = string(w + 2, '#');
  s[h + 1] = string(w + 2, '#');
  string t;
  for (int i = (1); i < ((h) + 1); i++) {
    cin >> t;
    s[i] = '#' + t + '#';
  }
  int ans = 0;
  for (int i = (1); i < ((h) + 1); i++)
    for (int j = (1); j < ((w) + 1); j++) {
      if (s[i][j] == '#') continue;
      for (int k = (1); k < ((h) + 1); k++)
        for (int l = (1); l < ((w) + 1); l++) {
          if (s[k][l] == '#') continue;
          deque<tuple<int, int, int>> q;
          q.emplace_back(i, j, 0);
          set<pair<int, int>> memo;
          memo.emplace(i, j);
          int r, c, t;
          while (!q.empty()) {
            tie(r, c, t) = q.front();
            q.pop_front();
            if (r == k && c == l) {
              chmax(ans, t);
              break;
            }
            auto p = make_pair(r - 1, c);
            if (s[r - 1][c] != '#' && memo.count(p) == 0) {
              memo.emplace(p);
              q.emplace_back(r - 1, c, t + 1);
            }
            p = make_pair(r + 1, c);
            if (s[r + 1][c] != '#' && memo.count(p) == 0) {
              memo.emplace(p);
              q.emplace_back(r + 1, c, t + 1);
            }
            p = make_pair(r, c - 1);
            if (s[r][c - 1] != '#' && memo.count(p) == 0) {
              memo.emplace(p);
              q.emplace_back(r, c - 1, t + 1);
            }
            p = make_pair(r, c + 1);
            if (c != w - 1 && s[r][c + 1] != '#' && memo.count(p) == 0) {
              memo.emplace(p);
              q.emplace_back(r, c + 1, t + 1);
            }
          }
        }
    }
  cout << ans << EOL;
}
