#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
using graph = vector<vector<int>>;
const ll mod = pow(10, 9) + 7;
const int INF = 1e9;
const ll LINF = 1e18;
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
ll H, W;
char f[20][20];
ll cnt[20][20][20][20];
ll bfs(ll sx, ll sy) {
  if (f[sy][sx] == '#') {
    return 0;
  }
  ll res = 0;
  bool seen[20][20] = {0};
  seen[sy][sx] = true;
  cnt[sy][sx][sy][sx] = 0;
  queue<pair<int, int>> que;
  que.push(make_pair(sx, sy));
  while (!que.empty()) {
    pair<ll, ll> current_pos = que.front();
    ll x = current_pos.first;
    ll y = current_pos.second;
    que.pop();
    seen[y][x] = true;
    for (int i = 0; i < (int)4; i++) {
      ll nx = x + dx[i];
      ll ny = y + dy[i];
      if (0 <= nx && W > nx && 0 <= ny && H > ny && f[ny][nx] == '.') {
        if (seen[ny][nx] != true) {
          que.push(make_pair(nx, ny));
          cnt[sy][sx][ny][nx] = cnt[sy][sx][y][x] + 1;
          res = max(res, cnt[sy][sx][ny][nx]);
        }
      }
    }
  }
  return res;
}
int main() {
  cin >> H >> W;
  ll ans = 0;
  for (int i = 0; i < (int)H; i++) {
    for (int j = 0; j < (int)W; j++) {
      cin >> f[i][j];
    }
  }
  for (int i = 0; i < (int)W; i++) {
    for (int j = 0; j < (int)H; j++) {
      ans = max(ans, bfs(i, j));
    }
  }
  cout << ans << endl;
}
