#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int dh[4] = {0, 1, 0, -1};
const int dw[4] = {1, 0, -1, 0};
int main(void) {
  int H, W;
  cin >> H >> W;
  string field[H];
  for (int i = 0; i < H; i++) cin >> field[i];
  int maxdistance = 0;
  for (int a = 0; a < H; a++) {
    for (int b = 0; b < W; b++) {
      pair<int, int> sp(a, b);
      vector<vector<int>> dist(H, vector<int>(W, -1));
      queue<pair<int, int>> q;
      q.push(sp);
      dist[a][b] = 0;
      while (!q.empty()) {
        pair<int, int> p = q.front();
        q.pop();
        int h = p.first, w = p.second;
        for (int k = 0; k < 4; k++) {
          int nh = h + dh[k];
          int nw = w + dw[k];
          if (nh < 0 || nh >= H || nw < 0 || nw >= W) continue;
          if (field[nh][nw] == '#') continue;
          if (dist[nh][nw] != -1) continue;
          dist[nh][nw] = dist[h][w] + 1;
          maxdistance = max(maxdistance, dist[nh][nw]);
          q.push(make_pair(nh, nw));
        }
      }
    }
  }
  cout << maxdistance << endl;
}
