#include <bits/stdc++.h>
using namespace std;
vector<vector<char>> S;
int H, W;
int p2v(int x, int y) { return y * W + x; }
vector<int> v2p(int v) { return {v % W, v / W}; }
int bfs(int Sx, int Sy) {
  vector<int> cost(H * W, -1);
  queue<int> que;
  cost[p2v(Sx, Sy)] = 0;
  que.push(p2v(Sx, Sy));
  int dx[4] = {-1, 0, 1, 0};
  int dy[4] = {0, -1, 0, 1};
  while (!que.empty()) {
    int v = que.front();
    que.pop();
    int x = v2p(v)[0];
    int y = v2p(v)[1];
    for (int i = 0; i < 4; i++) {
      if (x + dx[i] >= 0 && x + dx[i] < W && y + dy[i] >= 0 && y + dy[i] < H) {
        int nv = p2v(x + dx[i], y + dy[i]);
        if (cost[nv] == -1 && S[y + dy[i]][x + dx[i]] == '.') {
          que.push(nv);
          cost[nv] = cost[v] + 1;
        }
      }
    }
  }
  int m = 0;
  for (auto c : cost) {
    m = max(c, m);
  }
  return m;
}
int main() {
  cin >> H >> W;
  S.assign(H, vector<char>(W));
  for (int y = 0; y < H; y++) {
    for (int x = 0; x < W; x++) {
      cin >> S[y][x];
    }
  }
  int m = 0;
  for (int Sy = 0; Sy < H; Sy++) {
    for (int Sx = 0; Sx < W; Sx++) {
      if (S[Sy][Sx] == '#') break;
      m = max(m, bfs(Sx, Sy));
    }
  }
  cout << m << endl;
}
