#include <bits/stdc++.h>
using namespace std;
const long long BIGINF = 2e18 + 7;
const int INF = 2e9 + 7;
char mat[30][30];
const int dx[4] = {-1, 1, 0, 0};
const int dy[4] = {0, 0, -1, 1};
int h, w;
bool OK(int row, int col) {
  return (row >= 0 && row < h && col >= 0 && col < w && mat[row][col] == '.');
}
int main() {
  cin >> h >> w;
  for (int i = 0; i < h; i++) {
    cin >> mat[i];
  }
  int ans = 0;
  for (int row = 0; row < h; row++) {
    for (int col = 0; col < w; col++) {
      if (OK(row, col)) {
        vector<pair<int, int>> queue;
        queue.emplace_back(row, col);
        vector<vector<int>> distance(h, vector<int>(w));
        vector<vector<bool>> visited(h, vector<bool>(w));
        visited[row][col] = true;
        for (int i = 0; i < (int)queue.size(); i++) {
          pair<int, int> curr = queue[i];
          for (int direction = 0; direction < 4; direction++) {
            int new_row = curr.first + dx[direction];
            int new_col = curr.second + dy[direction];
            if (OK(new_row, new_col) && !visited[new_row][new_col]) {
              distance[new_col][new_row] =
                  distance[curr.first][curr.second] + 1;
              queue.emplace_back(new_col, new_row);
              visited[new_row][new_col] = true;
              ans = max(ans, distance[new_row][new_col]);
            }
          }
        }
      }
    }
  }
  cout << ans << "\n";
  return 0;
}
