#include <bits/stdc++.h>
using namespace std;
const int dx[4] = {-1, 1, 0, 0}, dy[4] = {0, 0, -1, 1};
int h, w, dist[25][25][25][25];
char grid[25][25];
queue<pair<int, int> > Q;
int main() {
  cin >> h >> w;
  for (int i = 1; i <= h; i++)
    for (int j = 1; j <= w; j++) cin >> grid[i][j];
  for (int i = 1; i <= h; i++)
    for (int j = 1; j <= w; j++) {
      while (!Q.empty()) Q.pop();
      Q.push(make_pair(i, j));
      dist[i][j][i][j] = 1;
      while (!Q.empty()) {
        pair<int, int> now = Q.front();
        Q.pop();
        int nx = now.first, ny = now.second;
        for (int k = 0; k < 4; k++) {
          int tx = nx + dx[k], ty = ny + dy[k];
          if (tx < 1 || tx > h || ty < 1 || ty > w) continue;
          if (dist[i][j][tx][ty]) continue;
          if (grid[tx][ty] == '#') continue;
          Q.push(make_pair(tx, ty));
          dist[i][j][tx][ty] = dist[i][j][nx][ny] + 1;
        }
      }
    }
  int mx = 0;
  for (int i = 1; i <= h; i++)
    for (int j = 1; j <= w; j++)
      for (int i2 = 1; i2 <= h; i2++)
        for (int j2 = 1; j2 <= w; j2++) mx = max(mx, dist[i][j][i2][j2]);
  cout << mx - 1 << endl;
  return 0;
}
