#include <bits/stdc++.h>
using namespace std;
int H, W;
int solve(char S[20][20], int h, int w) {
  queue<pair<int, int> > q;
  int m[20][20];
  for (int i = 0; i < 400; i++) {
    m[i / 20][i % 20] = 10000;
  }
  int imax = 0;
  m[h][w] = 0;
  q.push({h, w});
  while (!q.empty()) {
    auto i = q.front();
    if (i.first != 0 && S[i.first - 1][i.second] == '.' &&
        m[i.first - 1][i.second] > m[i.first][i.second] + 1) {
      m[i.first - 1][i.second] = m[i.first][i.second] + 1;
      q.push({i.first - 1, i.second});
    }
    if (i.first != H - 1 && S[i.first + 1][i.second] == '.' &&
        m[i.first + 1][i.second] > m[i.first][i.second] + 1) {
      m[i.first + 1][i.second] = m[i.first][i.second] + 1;
      q.push({i.first + 1, i.second});
    }
    if (i.second != 0 && S[i.first][i.second - 1] == '.' &&
        m[i.first][i.second - 1] > m[i.first][i.second] + 1) {
      m[i.first][i.second - 1] = m[i.first][i.second] + 1;
      q.push({i.first, i.second - 1});
    }
    if (i.second != W - 1 && S[i.first][i.second + 1] == '.' &&
        m[i.first][i.second + 1] > m[i.first][i.second] + 1) {
      m[i.first][i.second + 1] = m[i.first][i.second] + 1;
      q.push({i.first, i.second + 1});
    }
    if (m[i.first][i.second] > imax) {
      imax = m[i.first][i.second];
    }
    q.pop();
  }
  return imax;
}
int main() {
  cin >> H >> W;
  char S[20][20];
  for (int h = 0; h < H; h++) {
    for (int w = 0; w < W; w++) {
      cin >> S[h][w];
    }
  }
  int imax = 0;
  for (int h = 0; h < H; h++) {
    for (int w = 0; w < W; w++) {
      int res = solve(S, h, w);
      if (imax < res) {
        imax = res;
      }
    }
  }
  cout << imax << endl;
  return 0;
}
