#include <bits/stdc++.h>
using namespace std;
int main() {
  int H, W;
  cin >> H >> W;
  vector<string> S(H);
  for (int i = 0; i < H; i++) {
    cin >> S[i];
  }
  vector<vector<bool>> visited(H, vector<bool>(W, false));
  int ans = 0;
  const vector<int> dy = {1, 0, -1, 0};
  const vector<int> dx = {0, 1, 0, -1};
  for (int sy = 0; sy < H; sy++) {
    for (int sx = 0; sx < W; sx++) {
      if (!(0 <= sy && sy < H && 0 <= sx && sx < W)) continue;
      if (visited[sy][sx]) continue;
      if (S[sy][sx] == '#') continue;
      queue<pair<int, int>> Q;
      Q.push(make_pair(sy, sx));
      visited[sy][sx] = true;
      int tmp = 0;
      while (!Q.empty()) {
        int y = Q.front().first, x = Q.front().second;
        Q.pop();
        ans = max(ans, tmp);
        for (int i = 0; i < 4; i++) {
          int ny = y + dy[i], nx = x + dx[i];
          if (!(0 <= ny && ny < H && 0 <= nx && nx < W)) continue;
          if (S[ny][nx] == '#') continue;
          if (visited[ny][nx]) continue;
          Q.push(make_pair(ny, nx));
          visited[ny][nx] = true;
        }
        tmp++;
      }
      fill(visited.begin(), visited.end(), vector<bool>(W, false));
    }
  }
  cout << ans << endl;
}
