#include <bits/stdc++.h>
using namespace std;
struct node {
  int x, y;
} k;
queue<node> q;
const int MAX = 105;
int d[4][2] = {0, 1, 1, 0, -1, 0, 0 - 1};
int vis[MAX][MAX];
char s[MAX][MAX];
int n, m, ss = 0;
void bfs(int x, int y) {
  int i;
  memset(vis, 0, sizeof(vis));
  q.push({x, y});
  vis[x][y] = 0;
  while (!q.empty()) {
    k = q.front();
    q.pop();
    for (i = 0; i < 4; i++) {
      int xx = k.x + d[i][0];
      int yy = k.y + d[i][1];
      if (xx >= 0 && xx < n && yy >= 0 && yy < m && s[xx][yy] != '#' &&
          vis[xx][yy] == 0) {
        vis[xx][yy] = vis[k.x][k.y] + 1;
        if (ss < vis[xx][yy]) ss = vis[xx][yy];
        q.push({xx, yy});
      }
    }
  }
}
int main() {
  int i, j;
  cin >> n >> m;
  for (i = 0; i < n; i++) cin >> s[i];
  for (i = 0; i < n; i++)
    for (j = 0; j < m; j++) {
      if (s[i][j] == '.') bfs(i, j);
    }
  printf("%d\n", ss);
}
