#include <bits/stdc++.h>
using namespace std;
const long long N = 55;
long long n, m;
char a[N][N];
long long vis[N][N], dist[N][N], ways[N][N];
long long dx[4] = {-1, +1, 0, 0};
long long dy[4] = {0, 0, +1, -1};
long long bfs(long long x, long long y, long long n, long long m) {
  memset(vis, 0, sizeof(vis));
  queue<pair<long long, long long> > q;
  q.push({x, y});
  ways[x][y] = 1;
  vis[x][y] = 1;
  dist[x][y] = 0;
  long long mx = 0;
  while (!q.empty()) {
    long long x = q.front().first;
    long long y = q.front().second;
    q.pop();
    for (long long dir = 0; dir < 4; dir++) {
      long long nx = x + dx[dir];
      long long ny = y + dy[dir];
      if (nx < 1 || ny < 1 || nx > n || ny > m || a[nx][ny] == '#') continue;
      if (!vis[nx][ny]) {
        dist[nx][ny] = dist[x][y] + 1;
        mx = max(mx, 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 mx;
}
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  cin >> n >> m;
  for (long long i = 1; i <= n; i++)
    for (long long j = 1; j <= m; j++) cin >> a[i][j];
  long long ans = 0;
  for (long long i = 1; i <= n; i++)
    for (long long j = 1; j <= m; j++)
      if (a[i][j] == '.') {
        ans = max(ans, bfs(i, j, n, m));
        break;
      }
  cout << ans;
  return 0;
}
