#include <bits/stdc++.h>
using namespace std;
int h, w;
string s[20];
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};
int maze(int a, int b) {
  int dis[h][w];
  for (int i = 0; i < h; i++)
    for (int j = 0; j < w; j++) dis[i][j] = -1;
  dis[a][b] = 0;
  queue<pair<int, int> > que;
  que.push(pair<int, int>(a, b));
  int res = 0;
  while (!que.empty()) {
    pair<int, int> p = que.front();
    int x = p.first, y = p.second;
    int d = dis[x][y];
    que.pop();
    for (int i = 0; i < 4; i++) {
      int nx = x + dx[i], ny = y + dy[i];
      if (0 <= nx && nx < h && 0 <= ny && ny < w && s[nx][ny] == '.' &&
          dis[nx][ny] == -1) {
        que.push(pair<int, int>(nx, ny));
        dis[nx][ny] = d + 1;
        res = max(res, d + 1);
      }
    }
  }
  return res;
}
int main() {
  cin >> h >> w;
  for (int i = 0; i < h; i++) cin >> s[i];
  int ans = 0;
  for (int i = 0; i < h; i++)
    for (int j = 0; j < w; j++) {
      ans = max(ans, maze(i, j));
    }
  cout << ans << endl;
}
