#include <bits/stdc++.h>
using namespace std;
int res = 0;
const int MAX = 25;
bool visited[MAX][MAX];
int dx[4] = {-1, 0, 0, 1};
int dy[4] = {0, -1, 1, 0};
int h, w;
void bfs(int x, int y, vector<vector<char>>& grid) {
  queue<pair<int, pair<int, int>>> q;
  q.push({0, {x, y}});
  while (!q.empty()) {
    auto fr = q.front();
    int dist = fr.first;
    auto node = fr.second;
    x = node.first;
    y = node.second;
    q.pop();
    if (dist > res) {
      res = dist;
    }
    visited[x][y] = true;
    for (int k = 0; k < 4; ++k) {
      int nx = x + dx[k];
      int ny = y + dy[k];
      if (nx >= 0 && ny >= 0 && nx < h && ny < w && !visited[nx][ny] &&
          grid[nx][ny] == '.') {
        q.push({dist + 1, {nx, ny}});
      }
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  cin >> h >> w;
  vector<vector<char>> grid(h, vector<char>(w));
  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j) {
      cin >> grid[i][j];
    }
  }
  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j) {
      memset(visited, false, sizeof(visited));
      if (grid[i][j] == '.') {
        bfs(i, j, grid);
      }
    }
  }
  cout << res << "\n";
  return 0;
}
