#include <bits/stdc++.h>
using namespace std;
bool grid[25][25];
int dx[4] = {0, 0, -1, 1};
int dy[4] = {-1, 1, 0, 0};
int ans = 0;
void bfs(int row, int col) {
  bool visited[25][25];
  memset(visited, false, sizeof(visited));
  queue<pair<pair<int, int>, int>> q;
  q.push(make_pair(make_pair(row, col), 0));
  while (!q.empty()) {
    int vrow = q.front().first.first;
    int vcol = q.front().first.second;
    int dist = q.front().second;
    q.pop();
    if (!visited[vrow][vcol]) {
      visited[vrow][vcol] = true;
      ans = max(ans, dist);
      for (int i = 0; i < 4; ++i) {
        if (grid[vrow + dy[i]][vcol + dx[i]])
          q.push(make_pair(make_pair(vrow + dy[i], vcol + dx[i]), dist + 1));
      }
    }
  }
  return;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int h, w;
  cin >> h >> w;
  for (int i = 1; i <= h; ++i) {
    for (int j = 1; j <= w; ++j) {
      char c;
      cin >> c;
      if (c == '.') {
        grid[i][j] = true;
      }
    }
  }
  for (int i = 1; i <= h; ++i) {
    for (int j = 1; j <= w; ++j) {
      bfs(i, j);
    }
  }
  cout << ans << '\n';
  return 0;
}
