#include <bits/stdc++.h>
using namespace std;
set<int>::iterator its;
int h, w;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
char a[999][999];
int dis[999][999] = {0};
bool vis[999][999] = {false};
queue<pair<int, int>> q;
bool isvalid(int i, int j) {
  if (i < 0 || i >= h || j < 0 || j >= w)
    return 0;
  else
    return 1;
}
void bfs(int i, int j) {
  vis[i][j] = 1;
  dis[i][j] = 0;
  q.push({i, j});
  while (!q.empty()) {
    pair<int, int> p = q.front();
    int curi = p.first, curj = p.second;
    for (int k = 0; k < 4; k++) {
      if (isvalid(curi + dx[k], curj + dy[k]) &&
          a[curi + dx[k]][curj + dy[k]] != '#' &&
          !vis[curi + dx[k]][curj + dy[k]]) {
        dis[curi + dx[k]][curj + dy[k]] = dis[i][j] + 1;
        vis[curi + dx[k]][curj + dy[k]] = 1;
        q.push({curi + dx[k], curj + dy[k]});
      }
    }
  }
}
int main() {
  int ans = -1;
  cin >> h >> w;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      cin >> a[i][j];
    }
  }
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (a[i][j] == '#') continue;
      memset(dis, 0, h * w);
      memset(vis, false, h * w);
      bfs(i, j);
      int temp = -1;
      for (int k = 0; k < h; k++)
        for (int l = 0; l < w; l++) temp = max(temp, dis[k][l]);
      ans = max(ans, temp);
    }
  }
}
