#include <bits/stdc++.h>
using namespace std;
const int fx[5] = {1, -1, 0, 0}, fy[5] = {0, 0, 1, -1};
struct node {
  int x, y;
};
int n, m, ans = 0;
int d[25][25];
char p[25][25];
bool vis[25][25];
queue<node> q;
int main() {
  memset(p, 10, sizeof(p));
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) cin >> p[i][j];
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (p[i][j] == '#') continue;
      memset(d, 0, sizeof(d));
      memset(vis, 0, sizeof(vis));
      q.push((node){i, j});
      vis[i][j] = 1;
      while (!q.empty()) {
        node no = q.front();
        q.pop();
        for (int k = 0; k < 4; k++) {
          int nx = no.x + fx[k], ny = no.y + fy[k];
          if (nx < n && ny < m && nx >= 0 && ny >= 0 && p[nx][ny] == '.' &&
              !vis[nx][ny]) {
            vis[nx][ny] = 1;
            d[nx][ny] = d[no.x][no.y] + 1;
            ans = max(d[nx][ny], ans);
            q.push((node){nx, ny});
          }
        }
      }
    }
  }
  printf("%d", ans);
  return 0;
}
