#include <bits/stdc++.h>
using namespace std;
int h, w;
char ch[21][21];
int dx[] = {-1, 1, 0, 0};
int dy[] = {0, 0, -1, 1};
int bfs(int Startx, int Starty) {
  int dis[21][21] = {0}, visited[21][21] = {0}, Max = 0;
  queue<pair<int, int> > q;
  q.push({Startx, Starty});
  while (!q.empty()) {
    pair<int, int> t = q.front();
    q.pop();
    for (int i = 0; i < 4; i++) {
      int x = t.first + dx[i];
      int y = t.second + dy[i];
      if ((x >= 0 && x < h && y >= 0 && y < w) && !visited[x][y] &&
          (ch[x][y] == '.')) {
        dis[x][y] = dis[t.first][t.second] + 1;
        visited[x][y] = 1;
        q.push({x, y});
      }
    }
  }
  for (int i = 0; i < h; i++)
    for (int j = 0; j < w; j++) Max = max(Max, dis[i][j]);
  return Max;
}
int main() {
  ios_base ::sync_with_stdio(false);
  cin >> h >> w;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      cin >> ch[i][j];
    }
  }
  int res = 0;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      int ans = bfs(i, j);
      res = max(res, ans);
    }
  }
  cout << res << endl;
  return 0;
}
