#include <bits/stdc++.h>
using namespace std;
char field[25][25];
int dist[25][25];
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
int main() {
  int H, W;
  cin >> H >> W;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      cin >> field[i][j];
    }
  }
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      dist[i][j] = -1;
    }
  }
  queue<pair<int, int>> que;
  int ans = 0;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      que.push(make_pair(i, j));
      dist[i][j] = 0;
      while (!que.empty()) {
        pair<int, int> p = que.front();
        que.pop();
        for (int i = 0; i < 4; i++) {
          int nx = p.second + dx[i];
          int ny = p.first + dy[i];
          if (dist[ny][nx] != -1) continue;
          if (0 <= nx && nx < W && 0 <= ny && ny < H && field[ny][nx] != '#') {
            que.push(make_pair(ny, nx));
            dist[ny][nx] = dist[p.first][p.second] + 1;
          }
        }
      }
      int temp = 0;
      for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
          temp = max(temp, dist[i][j]);
        }
      }
      ans = max(ans, temp);
      for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
          dist[i][j] = -1;
        }
      }
    }
  }
  cout << ans << endl;
}
