#include <bits/stdc++.h>
using namespace std;
int w, h;
vector<vector<char>> s(23, vector<char>(23));
vector<vector<bool>> visited(23, vector<bool>(23, false));
vector<vector<int>> grid(23, vector<int>(23, 0));
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
queue<pair<int, int>> Q;
void bfs(int si, int sj) {
  Q.push(make_pair(si, sj));
  visited[si][sj] = true;
  while (!Q.empty()) {
    int nx, ny;
    tie(ny, nx) = Q.front();
    Q.pop();
    for (int(i) = 0; (i) < (4); (i)++) {
      int x = nx + dx[i];
      int y = ny + dy[i];
      if (0 <= x && x < w && 0 <= y && y < h && !visited[y][x] &&
          s[y][x] == '.') {
        grid[y][x] = grid[ny][nx] + 1;
        visited[y][x] = true;
        Q.push(make_pair(y, x));
      }
    }
  }
}
int main(void) {
  cin >> h >> w;
  for (int(i) = 0; (i) < (h); (i)++)
    for (int(j) = 0; (j) < (w); (j)++) cin >> s[i][j];
  int ans = 0;
  for (int(i) = 0; (i) < (h); (i)++)
    for (int(j) = 0; (j) < (w); (j)++) {
      for (int(ii) = 0; (ii) < (h); (ii)++)
        for (int(jj) = 0; (jj) < (w); (jj)++) visited[ii][jj] = false;
      for (int(ii) = 0; (ii) < (h); (ii)++)
        for (int(jj) = 0; (jj) < (w); (jj)++) grid[ii][jj] = 0;
      bfs(i, j);
      for (int(ii) = 0; (ii) < (h); (ii)++)
        for (int(jj) = 0; (jj) < (w); (jj)++) ans = max(ans, grid[ii][jj]);
    }
  cout << ans << endl;
  return 0;
}
