#include <bits/stdc++.h>
using namespace std;
long long int fastpow(long long int base, long long int exp, long long int M) {
  long long int res = 1;
  while (exp > 0) {
    if (exp & 1) res = (res * base) % M;
    base = (base * base) % M;
    exp >>= 1;
  }
  return res;
}
vector<long long int> par;
long long int root(long long int a) {
  while (a != par[a]) {
    par[a] = par[par[a]];
    a = par[a];
  }
  return a;
}
void unio(long long int a, long long int b) { par[root(a)] = root(b); }
long long int cnt = 0;
long long int n, m;
vector<vector<char>> matrix;
vector<vector<long long int>> vis, len;
void dfs(pair<long long int, long long int> p) {
  long long int x = p.first, y = p.second;
  vis[x][y] = 1;
  cnt = max(cnt, len[x][y]);
  if (x - 1 >= 0 && len[x - 1][y] == 0 && matrix[x - 1][y] == '.')
    len[x - 1][y] = len[x][y] + 1;
  if (x + 1 < n && len[x + 1][y] == 0 && matrix[x + 1][y] == '.')
    len[x + 1][y] = len[x][y] + 1;
  if (y - 1 >= 0 && len[x][y - 1] == 0 && matrix[x][y - 1] == '.')
    len[x][y - 1] = len[x][y] + 1;
  if (y + 1 < m && len[x][y + 1] == 0 && matrix[x][y + 1] == '.')
    len[x][y + 1] = len[x][y] + 1;
  if (x - 1 >= 0 && matrix[x - 1][y] == '.' && vis[x - 1][y] == 0) {
    dfs({x - 1, y});
  }
  if (x + 1 < n && matrix[x + 1][y] == '.' && vis[x + 1][y] == 0) {
    dfs({x + 1, y});
  }
  if (y - 1 >= 0 && matrix[x][y - 1] == '.' && vis[x][y - 1] == 0) {
    dfs({x, y - 1});
  }
  if (y + 1 < m && matrix[x][y + 1] == '.' && vis[x][y + 1] == 0) {
    dfs({x, y + 1});
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> n >> m;
  vis.resize(n, vector<long long int>(m));
  len.resize(n, vector<long long int>(m));
  matrix.resize(n, vector<char>(m));
  for (long long int i = 0; i <= n - 1; ++i)
    for (long long int j = 0; j <= m - 1; ++j) cin >> matrix[i][j];
  long long int ans = 0;
  for (long long int i = 0; i <= n - 1; ++i) {
    for (long long int j = 0; j <= m - 1; ++j) {
      if (matrix[i][j] == '.') {
        dfs({i, j});
        ans = max(cnt, ans);
        cnt = 0;
        for (long long int i = 0; i <= n - 1; ++i) {
          for (long long int j = 0; j <= m - 1; ++j) {
            vis[i][j] = 0;
            len[i][j] = 0;
          }
        }
      }
    }
  }
  cout << ans;
  return 0;
}
