#include <bits/stdc++.h>
using namespace std;
const int MAX = 1e5 + 5;
const int INF = 1001001001;
const int MOD = 1e9 + 7;
int H, W;
string S[25];
int bfs(int sy, int sx) {
  int res = 0;
  queue<pair<pair<int, int>, int>> q;
  q.push(make_pair(pair<int, int>(sy, sx), 0));
  bool used[25][25];
  for (int i = 0; i < (25); ++i) {
    for (int j = 0; j < (25); ++j) used[i][j] = false;
  }
  used[sy][sx] = true;
  int dy[4] = {-1, 0, 1, 0}, dx[4] = {0, -1, 0, 1};
  while (!q.empty()) {
    auto a = q.front();
    q.pop();
    pair<int, int> pos = a.first;
    int y = pos.first, x = pos.second;
    int cost = a.second;
    for (int d = 0; d < (4); ++d) {
      int ny = y + dy[d], nx = x + dx[d];
      if (0 <= ny && ny < H && 0 <= nx && nx < W && S[ny][nx] == '.' &&
          !used[ny][nx]) {
        used[ny][nx] = true;
        q.push(make_pair(pair<int, int>(ny, nx), cost + 1));
      }
    }
    res = max(res, cost);
  }
  return res;
}
int main() {
  cin >> H >> W;
  for (int i = 0; i < (H); ++i) cin >> S[i];
  int ans = 0;
  for (int y = 0; y < (H); ++y) {
    for (int x = 0; x < (W); ++x) {
      ans = max(ans, bfs(y, x));
    }
  }
  cout << ans << endl;
}
