#include <bits/stdc++.h>
using namespace std;
const int MAX_H = 20, MAX_W = 20;
const int INF = -1;
char maze[MAX_H][MAX_W];
int h, w;
int sx, sy;
int gx, gy;
int d[MAX_H][MAX_W];
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
int bfs() {
  queue<pair<int, int>> que;
  int max_d = 0;
  for (int(i) = 0; (i) < (h); (i)++) {
    for (int(j) = 0; (j) < (w); (j)++) {
      d[i][j] = INF;
    }
  }
  que.push(pair<int, int>(sx, sy));
  d[sx][sy] = 0;
  while (que.size()) {
    pair<int, int> p = que.front();
    que.pop();
    for (int(i) = 0; (i) < (4); (i)++) {
      int nx = p.first + dx[i], ny = p.second + dy[i];
      if (0 <= nx && nx < h && 0 <= ny && ny < w && maze[nx][ny] != '#' &&
          d[nx][ny] == INF) {
        que.push(pair<int, int>(nx, ny));
        d[nx][ny] = d[p.first][p.second] + 1;
      }
    }
  }
  for (int(i) = 0; (i) < (h); (i)++) {
    for (int(j) = 0; (j) < (w); (j)++) {
      if (max_d < d[i][j]) {
        max_d = d[i][j];
      }
    }
  }
  return max_d;
}
int main() {
  cin >> h >> w;
  for (int(i) = 0; (i) < (h); (i)++) {
    for (int(j) = 0; (j) < (w); (j)++) {
      cin >> maze[i][j];
    }
  }
  int max_d = 0;
  for (int(i) = 0; (i) < (h); (i)++) {
    for (int(j) = 0; (j) < (w); (j)++) {
      sx = i, sy = j;
      int d = bfs();
      if (max_d < d) {
        max_d = d;
      }
    }
  }
  cout << max_d << endl;
  return 0;
}
