#include <bits/stdc++.h>
using namespace std;
const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, 1, -1};
void dfs(int x, int y, vector<vector<bool>> &used, int len, int n, int m,
         vector<vector<char>> &a) {
  used[x][y] = true;
  for (int i = 0; i < 4; i++) {
    int x1 = x + dx[i];
    int y1 = y + dy[i];
    if (0 <= x1 && x1 < n && 0 <= y1 && y1 < m && !used[x1][y1] &&
        a[x1][y1] != '#') {
      dfs(x1, y1, used, len++, n, m, a);
    }
  }
}
int main() {
  int n, m;
  cin >> n >> m;
  vector<vector<char>> a(n, vector<char>(m));
  vector<vector<bool>> used(n, vector<bool>(m));
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) cin >> a[i][j];
  int best = 1e9;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) {
      int len = 0;
      if (!used[i][j]) {
        dfs(i, j, used, len, n, m, a);
        best = max(best, len);
      }
    }
  cout << best << endl;
  return 0;
}
