#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
  if (a % b == 0) return b;
  return gcd(b, a % b);
}
long long lcm(long long a, long long b) { return a * b / gcd(a, b); }
long long log(long long a) {
  long long b = a;
  long long cnt = 0;
  while (b % 2 == 0) {
    b /= 2;
    cnt++;
  }
  return cnt;
}
long long h, w;
char c[30][30];
set<pair<long long, long long>> st;
queue<pair<pair<long long, long long>, long long>> que;
vector<queue<pair<pair<long long, long long>, long long>>> empty(200000);
long long mx[]{-1, 1, 0, 0}, my[] = {0, 0, -1, 1};
long long bfs(pair<long long, long long> i, pair<long long, long long> j) {
  if (i == j) return 0;
  que.push(make_pair(i, 0));
  while (!que.empty()) {
    pair<long long, long long> p = que.front().first;
    long long dis = que.front().second;
    que.pop();
    if (p == j) return dis;
    for (long long k = 0; k < 4; k++) {
      if (st.find(make_pair(p.first + mx[k], p.second + my[k])) == st.end() &&
          c[p.first + mx[k]][p.second + my[k]] == '.') {
        que.push(
            make_pair(make_pair(p.first + mx[k], p.second + my[k]), dis + 1));
        st.insert(make_pair(p.first + mx[k], p.second + my[k]));
      }
    }
  }
  return 1000000000000;
}
long long ans = 0;
long long cnt = 0;
signed main() {
  cin >> h >> w;
  for (long long i = 0; i < h + 2; i++) {
    c[i][0] = '#';
    c[i][w + 1] = '#';
  }
  for (long long j = 0; j < w + 2; j++) {
    c[0][j] = '#';
    c[h + 1][j] = '#';
  }
  for (long long i = 0; i < h; i++) {
    for (long long j = 0; j < w; j++) {
      cin >> c[i + 1][j + 1];
    }
  }
  long long cnt = 0;
  for (long long sx = 0; sx < h; sx++) {
    for (long long sy = 0; sy < w; sy++) {
      for (long long gx = 0; gx < h; gx++) {
        for (long long gy = 0; gy < w; gy++) {
          if (c[sx + 1][sy + 1] == '.' && c[gx + 1][gy + 1] == '.') {
            long long bf =
                bfs(make_pair(sx + 1, sy + 1), make_pair(gx + 1, gy + 1));
            ans = max(ans, bf);
            st.clear();
            swap(que, empty[cnt]);
            cnt++;
          }
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}
