#include <bits/stdc++.h>
using namespace std;
int h, w;
int dirx[4] = {0, -1, 0, 1};
int diry[4] = {-1, 0, 1, 0};
int bfs(int i, int j, vector<vector<int>> maze) {
  queue<pair<int, int>> q;
  q.push({i, j});
  maze[i][j] = 1;
  int dist = 0;
  while (!q.empty()) {
    for (int k = 0; k < q.size(); k++) {
      pair<int, int> temp = q.front();
      q.pop();
      for (int m = 0; m < 4; m++) {
        int new_x = temp.first + dirx[m];
        int new_y = temp.second + diry[m];
        if (new_x < 0 || new_x >= h || new_y < 0 || new_y >= w ||
            maze[new_x][new_y])
          continue;
        q.push({new_x, new_y});
        maze[new_x][new_y] = 1;
      }
    }
    dist++;
  }
  return dist;
}
int main() {
  cin >> h >> w;
  vector<vector<int>> maze(h, vector<int>(w, 0));
  for (int i = 0; i < h; i++) {
    string temp;
    cin >> temp;
    for (int j = 0; j < w; j++) {
      if (temp[j] == '#') maze[i][j] = 1;
    }
  }
  int res = 0;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (maze[i][j] == 0) {
        res = max(res, bfs(i, j, maze));
      }
    }
  }
  cout << res << endl;
  return 0;
}
