#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization("unroll-loops")
using namespace std;
long long max3(long long x, long long y, long long z) {
  return max(max(x, y), z);
}
long long min3(long long x, long long y, long long z) {
  return min(min(x, y), z);
}
const long long N = 1e5 + 10, M = 2e5 + 10, M2 = 1e6 + 10, mod = 1e9 + 7,
                inf = 1e17 + 10;
const long long INF = 1e9 + 7;
void add(long long &a, long long b) {
  a += b;
  if (a >= mod) {
    a -= mod;
  }
}
template <typename Arg1>
void __f(const char *name, Arg1 &&arg1) {
  cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char *names, Arg1 &&arg1, Args &&...args) {
  const char *comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << " : " << arg1 << " | ";
  __f(comma + 1, args...);
}
long long X[] = {0, 1, 0, -1};
long long Y[] = {-1, 0, 1, 0};
long long power(long long x, long long n) {
  long long result = 1;
  while (n > 0) {
    if (n % 2 == 1) result = (result * x) % mod;
    x = ((x % mod) * (x % mod)) % mod;
    n = n / 2;
  }
  return result;
}
long long h, w;
string s[21];
long long vis[21][21], ways[21][21], dist[21][21];
long long bfs(long long x, long long y) {
  memset(vis, 0, sizeof(vis));
  queue<pair<long long, long long> > q;
  q.push({x, y});
  vis[x][y] = 1;
  dist[x][y] = 0;
  long long maxi = 0;
  while (!q.empty()) {
    long long x = q.front().first;
    long long y = q.front().second;
    q.pop();
    for (long long i = 0; i < 4; i++) {
      long long nx = x + X[i];
      long long ny = y + Y[i];
      if (nx < 0 || nx >= h || ny < 0 || ny >= w) continue;
      if (s[nx][ny] == '#') continue;
      if (!vis[nx][ny]) {
        dist[nx][ny] = dist[x][y] + 1;
        maxi = max(maxi, dist[nx][ny]);
        vis[nx][ny] = 1;
        ways[nx][ny] += ways[x][y];
        q.push({nx, ny});
      } else {
        if (dist[x][y] + 1 == dist[nx][ny]) ways[nx][ny] += ways[x][y];
      }
    }
  }
  return maxi;
}
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> h >> w;
  for (long long i = 0; i < h; i++) {
    cin >> s[i];
  }
  long long ans = 0;
  for (long long i = 0; i < h; i++) {
    for (long long j = 0; j < w; j++) {
      if (s[i][j] == '.') {
        ans = max(ans, bfs(i, j));
      }
    }
  }
  cout << ans;
  return 0;
}
