#include <bits/stdc++.h>
long long A, B, C, D, E, F, I, J, K, M, N, O, P, Q, R, S, T, U, V, X, Y, Z;
double dA, dB, dC, dD, dE, dF, dI, dJ, dK, dM, dN, dO, dP, dQ, dR, dS, dT, dU,
    dV, dX, dY, dZ;
using namespace std;
const string MINUSINF = "-";
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
void chmax(string& a, string b) {
  if (a == MINUSINF)
    a = b;
  else if (a.size() < b.size())
    a = b;
  else if (a.size() == b.size()) {
    if (a < b) a = b;
  }
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
int GCD(int a, int b) { return b ? GCD(b, a % b) : a; }
stack<long long> sta;
queue<long long> que;
deque<long long> dque;
set<string> s_set;
long long sum, sum1, sum2, sum3, sum4;
long long flg, flg1, flg2, flg3, cnt, cnt1, cnt2, cnt3, cnt4;
long long wk, wk1, wk2, wk3, wk4;
long long ans;
double dsum, dsum1, dsum2, dsum3, dsum4;
double dcnt, dcnt1, dcnt2, dcnt3, dcnt4;
double dwk, dwk1, dwk2, dwk3, dwk4;
double dans;
double dmax, dmax1;
double dmin, dmin1;
bool f;
long long weight[110], value[110];
long long a[100010][3];
long long n, h[100005];
vector<long long> p, c;
int vis[200001];
vector<string> first;
int Left[2100][2100], Right[2100][2100], Up[2100][2100], Down[2100][2100];
long long match[10] = {2, 5, 5, 4, 5, 6, 3, 7, 6};
vector<long long> box;
using namespace std;
int H, W;
char MAT[1000][1000];
char MAT2[1000][1000];
int depth[1000][1000];
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};
void BFS(queue<pair<int, int> > que) {
  while (!que.empty()) {
    pair<int, int> p = que.front();
    que.pop();
    for (int i = 0; i < 4; i++) {
      int nx = p.first + dx[i];
      int ny = p.second + dy[i];
      if (nx >= 0 && nx < H && ny >= 0 && ny < W && MAT2[nx][ny] != '#') {
        MAT2[nx][ny] = '#';
        depth[nx][ny] = depth[p.first][p.second] + 1;
        que.push(pair<int, int>(nx, ny));
      }
    }
  }
}
long long depth2;
int main() {
  queue<pair<int, int> > que;
  cin >> H >> W;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      cin >> MAT[i][j];
      MAT2[i][j] = MAT[i][j];
    }
  }
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      if (MAT[i][j] == '.') {
        for (int i = 0; i < H; i++) {
          for (int j = 0; j < W; j++) {
            depth[i][j] = 0;
          }
        }
        depth2 = 0;
        std::queue<pair<int, int> > empty;
        std::swap(que, empty);
        que.push(pair<int, int>(i, j));
        BFS(que);
        for (int i = 0; i < H; i++) {
          for (int j = 0; j < W; j++) {
            depth2 = (((depth[i][j]) > (depth2)) ? (depth[i][j]) : (depth2));
          }
        }
        ans = (((ans) > (depth2)) ? (ans) : (depth2));
        for (int i = 0; i < H; i++) {
          for (int j = 0; j < W; j++) {
            MAT2[i][j] = MAT[i][j];
          }
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}
