#include <bits/stdc++.h>
using namespace std;
int main() {
  int H, W, dist[20][20] = {};
  char S[20][20];
  cin >> H >> W;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      cin >> S[i][j];
    }
  }
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      if (S[i][j] == '#') break;
      int d[20][20] = {};
      int visited[20][20] = {};
      queue<pair<int, int> > q;
      d[i][j] = 0;
      q.push(pair<int, int>(i, j));
      visited[i][j] = 1;
      while (!q.empty()) {
        pair<int, int> pos = q.front();
        int x = pos.first;
        int y = pos.second;
        if (x - 1 >= 0) {
          if (S[x - 1][y] == '.' && visited[x - 1][y] == 0) {
            d[x - 1][y] = d[x][y] + 1;
            q.push(pair<int, int>(x - 1, y));
            visited[x - 1][y] = 1;
          }
        }
        if (x + 1 < H) {
          if (S[x + 1][y] == '.' && visited[x + 1][y] == 0) {
            d[x + 1][y] = d[x][y] + 1;
            q.push(pair<int, int>(x + 1, y));
            visited[x + 1][y] = 1;
          }
        }
        if (y - 1 >= 0) {
          if (S[x][y - 1] == '.' && visited[x][y - 1] == 0) {
            d[x][y - 1] = d[x][y] + 1;
            q.push(pair<int, int>(x, y - 1));
            visited[x][y - 1] = 1;
          }
        }
        if (y + 1 < W) {
          if (S[x][y + 1] == '.' && visited[x][y + 1] == 0) {
            d[x][y + 1] = d[x][y] + 1;
            q.push(pair<int, int>(x, y + 1));
            visited[x][y + 1] = 1;
          }
        }
        q.pop();
      }
      for (int a = 0; a < H; a++) {
        for (int b = 0; b < W; b++) {
          dist[i][j] = max(dist[i][j], d[a][b]);
        }
      }
    }
  }
  int ans = 0;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      ans = max(dist[i][j], ans);
    }
  }
  cout << ans << endl;
  return 0;
}
