#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
using namespace std;
const long long MOD = 1e9 + 7;
const long long mxN = 2e5 + 3;
long long dx[4] = {0, 1, 0, -1};
long long dy[4] = {1, 0, -1, 0};
string a[21];
long long bfs(long long i, long long j, long long h, long long w) {
  long long ans = 0;
  queue<pair<long long, long long>> qu;
  qu.push({i, j});
  long long dis[h][w];
  for (long long ii = 0; ii < h; ++ii) {
    for (long long jj = 0; jj < w; ++jj) {
      dis[ii][jj] = -1;
    }
  }
  dis[i][j] = 0;
  while (!qu.empty()) {
    pair<long long, long long> tp = qu.front();
    qu.pop();
    for (long long ii = 0; ii < 4; ++ii) {
      long long u = tp.first + dx[ii];
      long long v = tp.second + dy[ii];
      if (u < 0 or u >= h or v < 0 or v >= w) continue;
      if (dis[u][v] == -1 and a[u][v] == '.') {
        dis[u][v] = dis[tp.first][tp.second] + 1;
        ans = max(ans, dis[u][v]);
        qu.push({u, v});
      }
    }
  }
  return ans;
}
void solve() {
  long long h, w;
  cin >> h >> w;
  for (long long i = 0; i < h; ++i) {
    cin >> a[i];
  }
  long long ans = 0;
  for (long long i = 0; i < h; ++i) {
    for (long long j = 0; j < w; ++j) {
      if (a[i][j] == '.') {
        ans = max(ans, bfs(i, j, h, w));
      }
    }
  }
  cout << ans << "\n";
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long nT = 1;
  for (long long i = 1; i <= nT; ++i) solve();
  return 0;
}
