#include <bits/stdc++.h>
using namespace std;
int h, w, ans, curr, dist[20][20];
bool visited[20][20];
char m[20][20];
queue<pair<int, int>> q;
void bfsClear() {
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      visited[i][j] = false;
    }
  }
  while (!q.empty()) {
    q.pop();
  }
}
void bfsCheck(int a, int b, int aPrev, int bPrev) {
  if (m[a][b] == '.' && visited[a][b] == false) {
    visited[a][b] = true;
    dist[a][b] = dist[aPrev][bPrev] + 1;
    q.push({a, b});
  }
}
void bfs(int a, int b) {
  bfsClear();
  visited[a][b] = true;
  dist[a][b] = 0;
  q.push({a, b});
  while (!q.empty()) {
    int A = q.front().first;
    int B = q.front().second;
    curr = max(curr, dist[A][B]);
    q.pop();
    bfsCheck(A + 1, B, A, B);
    bfsCheck(A - 1, B, A, B);
    bfsCheck(A, B + 1, A, B);
    bfsCheck(A, B - 1, A, B);
  }
}
int main() {
  cin >> h >> w;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      cin >> m[i][j];
    }
  }
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (m[i][j] == '.') {
        bfs(i, j);
        ans = max(ans, curr);
        curr = 0;
      }
    }
  }
  cout << ans << "\n";
  return 0;
}
