#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
long long GCD(long long a, long long b) { return b ? GCD(b, a % b) : a; }
long long LCM(long long a, long long b) { return a / GCD(a, b) * b; }
int dx[8] = {-1, 0, 1, 0, 1, 1, -1, -1};
int dy[8] = {0, -1, 0, 1, 1, -1, 1, -1};
char dir[4] = {'u', 'l', 'd', 'r'};
long long int cmp1(pair<long long int, string> a,
                   pair<long long int, string> b) {
  if (a.first != b.first)
    return a.first < b.first;
  else
    return a.second < b.second;
}
long long modpow(long long a, long long n) {
  long long res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % 1000000007;
    a = a * a % 1000000007;
    n >>= 1;
  }
  return res;
}
bool color[60][60];
int h, w;
char s[200][100];
int ans = 0;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> h >> w;
  int ans = 0;
  for (int i = 0; i < h; i++)
    for (int j = 0; j < w; j++) {
      cin >> s[i][j];
    }
  int d[60][60];
  memset(d, 0, sizeof(d));
  queue<pair<int, int> > Q;
  memset(color, 0, sizeof(color));
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (s[i][j] == '#') continue;
      if (color[i][j]) continue;
      Q.push(make_pair(i, j));
      color[i][j] = 1;
      int tmp = 0;
      int cnt = 0;
      while (!Q.empty()) {
        pair<int, int> p = Q.front();
        Q.pop();
        bool abc = 0;
        for (int i = 0; i < 4; i++) {
          int nx = p.first + dx[i];
          int ny = p.second + dy[i];
          if (nx >= 0 && ny >= 0 && nx < h && ny < w) {
            if (s[nx][ny] == '#') continue;
            if (color[nx][ny]) {
              continue;
            } else {
              color[nx][ny] = 1;
              d[nx][ny] = d[p.first][p.second] + 1;
              Q.push(make_pair(nx, ny));
              abc = 1;
            }
          }
        }
        if (abc == 0) tmp += d[p.first][p.second];
      }
      ans = (ans > tmp ? ans : tmp);
    }
  }
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      ans = (ans > d[i][j] ? ans : d[i][j]);
    }
  }
  cout << ans << endl;
  return 0;
}
