#include <bits/stdc++.h>
using namespace std;
int h, w;
char grid[25][25];
int b[405][25][25];
int sx, sy;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
int bfs(int t) {
  queue<pair<int, int> > que;
  que.push(pair<int, int>(sx, sy));
  b[t][sx][sy] = 0;
  while (que.size()) {
    pair<int, int> p = que.front();
    que.pop();
    int nx = p.first;
    int ny = p.second;
    for (int i = 0; i <= 3; i++) {
      int nex = dx[i];
      int ney = dy[i];
      if (b[t][nx + nex][ny + ney] == -1 && grid[nx + nex][ny + ney] != '#') {
        que.push(pair<int, int>(nx + nex, ny + ney));
        b[t][nx + nex][ny + ney] = b[t][nx][ny] + 1;
      }
    }
  }
  return 0;
}
int main() {
  cin >> h >> w;
  for (int i = 0; i <= h + 1; i++) {
    for (int j = 0; j <= w + 1; j++) {
      grid[i][j] = '#';
    }
  }
  for (int i = 1; i <= h; i++) {
    for (int j = 1; j <= w; j++) {
      cin >> grid[i][j];
    }
  }
  for (int i = 1; i <= h * w; i++) {
    for (int j = 0; j <= h + 1; j++) {
      for (int k = 0; k <= w + 1; k++) {
        b[i][j][k] = -1;
      }
    }
  }
  int ans = 0;
  int time = 0;
  for (int i = 1; i <= h; i++) {
    for (int j = 1; j <= w; j++) {
      sx = i;
      sy = j;
      time++;
      bfs(time);
      for (int k = 1; k <= h; k++) {
        for (int l = 1; l <= w; l++) {
          ans = max(ans, b[time][k][l]);
        }
      }
    }
  }
  cout << ans << endl;
}
