#include <bits/stdc++.h>
using namespace std;
int MOD = 1000000007;
int h, w;
vector<string> maze(30);
vector<vector<int>> has(30, vector<int>(30));
vector<vector<int>> dist(30, vector<int>(30));
int movex[] = {-1, 1, 0, 0};
int movey[] = {0, 0, -1, 1};
int maxv = 0;
int bfs(int x, int y, int len) {
  queue<vector<int>> q;
  has[x][y] = 1;
  q.push({x, y});
  while (!q.empty()) {
    auto pa = q.front();
    q.pop();
    int x = pa[0];
    int y = pa[1];
    has[x][y] = 1;
    for (int i = 0; i < 4; i++) {
      int nx = x + movex[i];
      int ny = y + movey[i];
      if (nx >= 0 && nx < h && ny >= 0 && ny < w) {
        if (maze[nx][ny] == '.' && has[nx][ny] == 0) {
          dist[nx][ny] = dist[x][y] + 1;
          maxv = max(maxv, dist[nx][ny]);
          q.push({nx, ny});
        }
      }
    }
  }
  return 0;
}
int main() {
  cin >> h >> w;
  for (int i = 0; i < h; i++) {
    cin >> maze[i];
  }
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (maze[i][j] == '.') {
        for (int k = 0; k < h; k++) {
          for (int l = 0; l < w; l++) {
            has[k][l] = 0;
            dist[k][l] = 0;
          }
        }
        bfs(i, j, 0);
      }
    }
  }
  cout << maxv << endl;
  return 0;
}
