#include <bits/stdc++.h>
using namespace std;
int fx[] = {1, -1, 0, 0}, fy[] = {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, 0x3f, sizeof(p));
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) scanf("%d", &p[i][j]);
  for (int i = 0; i < n; i++) {
    for (int j = 0; 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 xx = no.x + fx[k], yy = no.y + fy[k];
          if (xx < n && yy < m && xx >= 0 && yy >= 0 && p[xx][yy] == '.' &&
              !vis[xx][yy]) {
            vis[xx][yy] = 1;
            d[xx][yy] = d[no.x][no.y] + 1;
            ans = max(d[xx][yy], ans);
            q.push((node){xx, yy});
          }
        }
      }
    }
  }
  printf("%d", ans);
  return 0;
}
