#include <bits/stdc++.h>
using namespace std;
const int dh[4] = {0, 1, 0, -1};
const int dw[4] = {1, 0, -1, 0};
int H, W;
vector<string> M;
int main() {
  cin >> H >> W;
  M.resize(H);
  for (int h = 0; h < (H); h++) cin >> M[h];
  int max_dist = 0;
  for (int h = 0; h < (H); h++)
    for (int w = 0; w < (W); w++) {
      vector<vector<int>> dist(H, vector<int>(W, -1));
      queue<pair<int, int>> que;
      que.push(make_pair(h, w));
      dist[h][w] = 0;
      while (!que.empty()) {
        pair<int, int> p = que.front();
        que.pop();
        for (int i = 0; i < (4); i++) {
          int nh = p.first + dh[i];
          int nw = p.second + dw[i];
          if (nh < 0 || nh >= H || nw < 0 || nw >= W) continue;
          if (M[nh][nw] == '#') continue;
          if (dist[nh][nw] != -1) continue;
          dist[nh][nw] = dist[p.first][p.second] + 1;
          que.push(make_pair(nh, nw));
        }
      }
      for (int i = 0; i < (H); i++)
        for (int j = 0; j < (W); j++) {
          if (dist[i][j] > max_dist) max_dist = dist[i][j];
        }
    }
  cout << max_dist << endl;
}
