#include <bits/stdc++.h>
using intl = long long;
using itnl = long long;
using itn = int;
using ld = long double;
using namespace std;
const intl INF = 1e9;
const intl MOD = 1e9 + 7;
const ld EPS = 1.0e-14;
const ld PI = acos(-1);
void fp(bool f) { cout << (f ? "Yes" : "No") << endl; }
void fp(bool f, string s, string t) { cout << (f ? s : t) << endl; }
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;
}
intl gcd(intl a, intl b) {
  if (!b) return a;
  return gcd(b, a % b);
}
intl lcm(intl a, intl b) { return a / gcd(a, b) * b; }
intl kai(intl k) {
  intl a = 1;
  for (int i = 2; i <= k; i++) {
    a *= i;
  }
  return a;
}
intl digit10(intl a) {
  intl b = 0;
  do {
    a /= 10;
    b++;
  } while (a);
  return b;
}
signed main() {
  cout << fixed << setprecision(10);
  intl h, w;
  cin >> h >> w;
  bool s[h + 2][w + 2];
  memset(s, 0, sizeof(s));
  for (intl i = 0; i < (intl)(h); i++) {
    for (intl j = 0; j < (intl)(w); j++) {
      char c;
      cin >> c;
      s[i + 1][j + 1] = (c == '.');
    }
  }
  intl mturn = 0;
  vector<pair<intl, intl> > move = {{0, 1}, {1, 0}, {-1, 0}, {0, -1}};
  for (intl i = (intl)(1); i < (intl)(h + 1); i++) {
    for (intl j = (intl)(1); j < (intl)(w + 1); j++) {
      if (!s[i][j]) continue;
      queue<pair<intl, intl> > q;
      q.push(make_pair(i, j));
      intl turn = -1;
      bool board[h + 2][w + 2];
      memcpy(board, s, sizeof(board));
      while (!q.empty()) {
        turn++;
        intl len = q.size();
        for (intl k = 0; k < (intl)(len); k++) {
          pair<intl, intl> p = q.front();
          q.pop();
          for (auto l : move) {
            intl fir = l.first + p.first;
            intl sec = l.second + p.second;
            if (!board[fir][sec]) continue;
            board[fir][sec] = false;
            q.push(make_pair(fir, sec));
          }
        }
      }
      mturn = max(mturn, turn);
    }
  }
  cout << mturn << endl;
  return 0;
}
