#include <bits/stdc++.h>
using namespace std;
mt19937 rng32(chrono::steady_clock::now().time_since_epoch().count());
long long inf = 1e18, MOD = 1e9 + 7;
long long n, m, k, ar[1000005], br[1000005], vis[20][20];
string s[20], s1;
void in() {
  for (long long i = 0; i < n; i++)
    for (long long j = 0; j < m; j++) vis[i][j] = inf;
}
bool check(long long r, long long c) {
  if (r >= 0 && r < n && c >= 0 && c < m && s[r][c] != '#')
    return true;
  else
    return false;
}
long long move(int r, int c, int tr, int tc) {
  if (s[r][c] == '#' || s[tr][tc] == '#') return 0;
  in();
  queue<pair<long long, long long> > q;
  q.push(make_pair(r, c));
  vis[r][c] = 0;
  while (!q.empty()) {
    pair<long long, long long> cur = q.front();
    q.pop();
    if (cur.first == tr && cur.second == tc) break;
    if (check(cur.first, cur.second + 1)) {
      q.push(make_pair(cur.first, cur.second + 1));
      vis[cur.first][cur.second + 1] =
          min(vis[cur.first][cur.second + 1], vis[cur.first][cur.second] + 1);
    }
    if (check(cur.first, cur.second - 1)) {
      q.push(make_pair(cur.first, cur.second - 1));
      vis[cur.first][cur.second - 1] =
          min(vis[cur.first][cur.second - 1], vis[cur.first][cur.second] + 1);
    }
    if (check(cur.first + 1, cur.second)) {
      q.push(make_pair(cur.first + 1, cur.second));
      vis[cur.first + 1][cur.second] =
          min(vis[cur.first + 1][cur.second], vis[cur.first][cur.second] + 1);
    }
    if (check(cur.first - 1, cur.second)) {
      q.push(make_pair(cur.first - 1, cur.second));
      vis[cur.first - 1][cur.second] =
          min(vis[cur.first - 1][cur.second], vis[cur.first][cur.second] + 1);
    }
  }
  if (vis[tr][tc] >= inf)
    return 0;
  else
    return vis[tr][tc];
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int ti = 1;
  while (ti--) {
    cin >> n >> m;
    long long ans = 0;
    for (long long i = 0; i < n; i++) cin >> s[i];
    for (long long i = 0; i < n; i++)
      for (long long j = 0; j < m; j++)
        for (long long ii = 0; ii < n; ii++)
          for (long long jj = 0; jj < m; jj++)
            ans = max(ans, move(i, j, ii, jj));
    cout << ans << endl;
  }
  return 0;
}
