#include <bits/stdc++.h>
using namespace std;
const long long dx[4] = {-1, 1, 0, 0};
const long long dy[4] = {0, 0, -1, 1};
char grid[25][25];
bool valid(long long row, long long col, long long H, long long W) {
  return (row >= 0 && col >= 0 && row < H && col < W && grid[row][col] == '.');
}
void BFS(long long row, long long col, long long H, long long W,
         long long& ans) {
  vector<vector<long long>> dist(H, vector<long long>(W, -1));
  dist[row][col] = 0;
  queue<pair<long long, long long>> q;
  q.push({row, col});
  while (!q.empty()) {
    pair<long long, long long> nodo = q.front();
    q.pop();
    for (long long i = 0; i < 4; i++) {
      pair<long long, long long> dir = {nodo.first + dx[i],
                                        nodo.second + dy[i]};
      if (valid(dir.first, dir.second, H, W) &&
          dist[dir.first][dir.second] == (-1)) {
        dist[dir.first][dir.second] = dist[nodo.first][nodo.second] + 1;
        q.push({dir.first, dir.second});
        ans = max(ans, dist[dir.first][dir.second]);
      }
    }
  }
}
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long H, W;
  cin >> H >> W;
  for (long long i = 0; i < H; i++) {
    for (long long j = 0; j < W; j++) {
      cin >> grid[i][j];
    }
  }
  long long ans = 0;
  for (long long i = 0; i < H; i++) {
    for (long long j = 0; j < W; j++) {
      BFS(i, j, H, W, ans);
    }
  }
  cout << ans << '\n';
  return 0;
}
