#include <bits/stdc++.h>
using namespace std;
const int maxn = 25;
int n, m, ans = 0;
int step[maxn][maxn];
char grid[maxn][maxn];
queue<pair<int, int> > q;
int dx[4] = {0, 0, -1, 1};
int dy[4] = {-1, 1, 0, 0};
void init(int x, int y) {
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      step[i][j] = 1e9;
    }
  }
  step[x][y] = 0;
  while (!q.empty()) {
    q.pop();
  }
  q.push(make_pair(x, y));
}
bool isvalid(int x, int y) {
  return x >= 0 && x < n && y >= 0 && y < m && step[x][y] == 1e9 &&
         grid[x][y] == '.';
}
void BFS(int x, int y) {
  init(x, y);
  while (!q.empty()) {
    pair<int, int> t = q.front();
    int nx = t.first, ny = t.second;
    q.pop();
    for (int i = 0; i < 4; i++) {
      int tx = nx + dx[i], ty = ny + dy[i];
      if (isvalid(tx, ty)) {
        step[tx][ty] = step[nx][ny] + 1;
        q.push(make_pair(tx, ty));
      }
    }
  }
}
int FindMax() {
  int mx = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (step[i][j] != 1e9) mx = max(mx, step[i][j]);
    }
  }
  return mx;
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; i++) {
    scanf("%s", grid[i]);
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      BFS(i, j);
      ans = max(ans, FindMax());
    }
  }
  printf("%d\n", ans);
  return 0;
}
