#include <bits/stdc++.h>
using namespace std;
int h, w;
char grid[25][25];
const int dx[4] = {1, -1, 0, 0};
const int dy[4] = {0, 0, 1, -1};
int main() {
  cin >> h >> w;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      cin >> grid[i][j];
    }
  }
  int ans = 0;
  auto is_good = [&](int row, int col) {
    return row >= 0 && col >= 0 && row < h && col < w && grid[row][col] == '.';
  };
  for (int s_row = 0; s_row < h; s_row++) {
    for (int s_col = 0; s_col < w; s_col++) {
      if (is_good(s_row, s_col)) {
        vector<pair<int, int>> q;
        q.emplace_back(s_row, s_col);
        vector<vector<bool>> vis(h, vector<bool>(w));
        vector<vector<int>> dist(h, vector<int>(w));
        for (int i = 0; i < (int)q.size(); i++) {
          pair<int, int> me = q[i];
          for (int dir = 0; dir < 4; dir++) {
            int row2 = me.first + dx[dir];
            int col2 = me.second + dy[dir];
            if (is_good(row2, col2) && !vis[row2][col2]) {
              dist[row2][col2] = dist[me.first][me.second] + 1;
              vis[row2][col2] = true;
              ans = max(ans, dist[row2][col2]);
              q.emplace_back(row2, col2);
            }
          }
        }
      }
    }
  }
  cout << ans << endl;
}
