#include <bits/stdc++.h>
using namespace std;
int mx[4] = {0, 1, 0, -1}, my[4] = {1, 0, -1, 0};
int h, w, ans;
string s[30];
bool vis[30][30];
void bfs(int u) {
  queue<pair<int, int> > q;
  q.push(make_pair(u, 0));
  vis[u / w][u % w] = 1;
  int v, k = 0;
  while (!q.empty()) {
    int x = q.front().first / w, y = q.front().first % w;
    int d = q.front().second;
    q.pop();
    for (int i = 0; i < 4; ++i) {
      int xx = x + mx[i], yy = y + my[i];
      if (xx < 0 || yy < 0 || xx >= h || yy >= w || vis[xx][yy] ||
          s[xx][yy] == '#')
        continue;
      vis[xx][yy] = 1;
      if (d + 1 > k) k = d + 1, v = xx * w + yy;
      q.push(make_pair(xx * w + yy, d + 1));
    }
  }
  q.push(make_pair(v, 0));
  memset(vis, 0, sizeof(vis));
  vis[v / w][v % w] = 1;
  while (!q.empty()) {
    int x = q.front().first / w, y = q.front().first % w;
    int d = q.front().second;
    q.pop();
    for (int i = 0; i < 4; ++i) {
      int xx = x + mx[i], yy = y + my[i];
      if (xx < 0 || yy < 0 || xx >= h || yy >= w || vis[xx][yy] ||
          s[xx][yy] == '#')
        continue;
      vis[xx][yy] = 1;
      ans = max(ans, d + 1);
      q.push(make_pair(xx * w + yy, d + 1));
    }
  }
}
int main() {
  cin >> h >> w;
  for (int i = 0; i < h; ++i) cin >> s[i];
  for (int i = 0; i < h; ++i)
    for (int j = 0; j < w; ++j)
      if (!vis[i][j]) bfs(i * w + j);
  cout << ans;
  return 0;
}
