#include <bits/stdc++.h>
using namespace std;
const int INF = int(1e9) + int(1e5);
const long long INFL = long long(2e18) + long long(1e10);
const unsigned int MOD = 1E9 + 7;
const double EPS = 1e-9;
std::mt19937_64 generator(
    std::chrono::system_clock::now().time_since_epoch().count());
inline long long powmod(long long a, long long b, long long mod) {
  long long res = 1;
  a %= mod;
  assert(b >= 0);
  for (; b; b >>= 1) {
    if (b & 1) res = res * a % mod;
    a = a * a % mod;
  }
  return res;
}
long long gcd(long long a, long long b) { return a ? gcd(b % a, a) : b; }
long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
void READ(bool _local) {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
}
int n, m;
string s[21];
int getmx(int a, int b) {
  vector<vector<int> > d(n, vector<int>(m));
  for (int i = 0; i < (n); ++i)
    for (int j = 0; j < (m); ++j) {
      if (s[i][j] == '.')
        d[i][j] = -1;
      else
        d[i][j] = INF;
    }
  d[a][b] = 0;
  queue<pair<int, int> > q;
  q.push(make_pair(a, b));
  int ret = 0;
  while (!q.empty()) {
    pair<int, int> p = q.front();
    q.pop();
    int dd = d[p.first][p.second];
    ret = max(ret, dd);
    ++dd;
    if (p.first && d[p.first - 1][p.second] == -1) {
      d[p.first - 1][p.second] = dd;
      q.push(make_pair(p.first - 1, p.second));
    }
    if (p.first + 1 < n && d[p.first + 1][p.second] == -1) {
      d[p.first + 1][p.second] = dd;
      q.push(make_pair(p.first + 1, p.second));
    }
    if (p.second && d[p.first][p.second - 1] == -1) {
      d[p.first][p.second - 1] = dd;
      q.push(make_pair(p.first, p.second - 1));
    }
    if (p.second + 1 < m && d[p.first][p.second + 1] == -1) {
      d[p.first][p.second + 1] = dd;
      q.push(make_pair(p.first, p.second + 1));
    }
  }
  return ret;
}
int main() {
  READ(1);
  cin >> n >> m;
  for (int i = 0; i < (n); ++i) cin >> s[i];
  int mx = 0;
  for (int i = 0; i < (n); ++i)
    for (int j = 0; j < (m); ++j) mx = max(mx, getmx(i, j));
  cout << mx;
}
