#include <bits/stdc++.h>
using namespace std;
const int H_MAX = 20;
const int W_MAX = 20;
vector<vector<char>> S(H_MAX + 5, vector<char>(W_MAX + 5, '#'));
vector<vector<int>> dist(H_MAX, vector<int>(W_MAX, -1));
vector<pair<int, int>> d_que = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};
int main() {
  int H, W;
  cin >> H >> W;
  for (int i = (1); i < (int)(H + 1); i++) {
    for (int j = (1); j < (int)(W + 1); j++) {
      cin >> S[i][j];
    }
  }
  int ans = 0;
  for (int i = (1); i < (int)(H + 1); i++) {
    for (int j = (1); j < (int)(W + 1); j++) {
      if (S[i][j] == '#') continue;
      queue<pair<int, int>> que;
      dist.assign(H_MAX, vector<int>(W_MAX, -1));
      dist[i][j] = 0;
      que.push({i, j});
      while (!que.empty()) {
        int x = que.front().first;
        int y = que.front().second;
        ans = max(ans, dist[x][y]);
        que.pop();
        for (int j = 0; j < (int)(4); j++) {
          int x_next = x + d_que[j].first;
          int y_next = y + d_que[j].second;
          if (dist[x_next][y_next] != -1) continue;
          if (S[x_next][y_next] == '#') continue;
          dist[x_next][y_next] = dist[x][y] + 1;
          que.push({x_next, y_next});
        }
      }
    }
  }
  cout << ans << endl;
}
