#include <bits/stdc++.h>
using namespace std;
static const int INF = INT_MAX;
static const long long LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const long long LMIN = LLONG_MIN;
static const int MOD = 1000000007;
static const int SIZE = 200005;
const int dx[] = {0, -1, 1, 0};
const int dy[] = {-1, 0, 0, 1};
long long fac[SIZE], finv[SIZE], inv[SIZE];
void combInit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < SIZE; ++i) {
    fac[i] = (fac[i - 1] * i) % MOD;
    inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
    finv[i] = (finv[i - 1] * inv[i]) % MOD;
  }
}
long long comb(int n, int k) {
  if (n < k) return 0;
  if (n < 0 || k < 0) return 0;
  return (fac[n] * (finv[k] * finv[n - k] % MOD)) % MOD;
}
vector<int> Div(int n) {
  vector<int> ret;
  for (int i = 1; i * i <= n; ++i) {
    if (n % i == 0) {
      ret.push_back(i);
      if (i * i != n) ret.push_back(n / i);
    }
  }
  sort(ret.begin(), ret.end());
  return ret;
}
int bfs(int h, int w);
int mp[25][25];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int h, w;
  cin >> h >> w;
  int mx = 0;
  for (int i = 0; i < 25; ++i) {
    for (int j = 0; j < 25; ++j) {
      mp[i][j] = -1;
    }
  }
  for (int i = 1; i <= h; ++i) {
    for (int j = 1; j <= w; ++j) {
      char c;
      cin >> c;
      if (c == '.') mp[i][j] = 0;
    }
  }
  for (int i = 1; i <= h; ++i) {
    for (int j = 1; j <= w; ++j) {
      int tmp = bfs(i, j);
      mx = max(tmp, mx);
    }
  }
  cout << mx << '\n';
  return 0;
}
int bfs(int h, int w) {
  queue<pair<pair<int, int>, int> > q;
  q.push(make_pair(make_pair(h, w), 0));
  bool vi[25][25] = {};
  int cst[25][25] = {};
  while (!q.empty()) {
    pair<pair<int, int>, int> p = q.front();
    q.pop();
    vi[p.first.first][p.first.second] = true;
    cst[p.first.first][p.first.second] = p.second;
    for (int i = 0; i < 4; ++i) {
      if (mp[p.first.first + dx[i]][p.first.second + dy[i]] == -1) continue;
      if (!vi[p.first.first + dx[i]][p.first.second + dy[i]]) {
        q.push(
            make_pair(make_pair(p.first.first + dx[i], p.first.second + dy[i]),
                      p.second + 1));
        vi[p.first.first][p.first.second] = true;
      }
    }
  }
  int mx = 0;
  for (int i = 0; i < 25; ++i) {
    for (int j = 0; j < 25; ++j) {
      mx = max(mx, cst[i][j]);
    }
  }
  return mx;
}
