#include <bits/stdc++.h>
using namespace std;
long long a[100001], b[100001], c[100001], d, n, m, x, y, z, h, w, k, sum,
    mi = (long long)1e9, ma = -(long long)1e9, ans, s, t, l, r, res, tmp, itr,
    p, q;
bool flag;
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
int dx8[8] = {1, 1, 0, -1, -1, -1, 0, 1}, dy8[8] = {0, 1, 1, 1, 0, -1, -1, -1};
char cha;
string st;
pair<long long, long long> pa;
long long first[25][25];
long long fic[25][25];
bool condition(long long x, long long y) {
  if (x < 0 || x >= w || y < 0 || y >= h)
    return 0;
  else if (fic[x][y] > 0)
    return 0;
  else if (first[x][y] == 1)
    return 0;
  else
    return 1;
}
void bfs(long long i, long long j) {
  queue<pair<long long, long long> > sta;
  for (long long k = long long(0); k < long long(w); ++k)
    for (long long l = long long(0); l < long long(h); ++l) fic[k][l] = 0;
  fic[i][j] = 1;
  sta.push({i, j});
  long long nx, ny;
  while (!sta.empty()) {
    pa = sta.front();
    sta.pop();
    x = pa.first;
    y = pa.second;
    for (long long ind = long long(0); ind < long long(4); ++ind) {
      nx = x + dx[ind];
      ny = y + dy[ind];
      if (condition(nx, ny)) {
        sta.push({nx, ny});
        fic[nx][ny] = fic[x][y] + 1;
      }
    }
  }
  for (long long k = long long(0); k < long long(w); ++k)
    for (long long l = long long(0); l < long long(h); ++l)
      ma = max(ma, fic[k][l]);
}
int main(void) {
  cin >> w >> h;
  for (long long i = long long(0); i < long long(w); ++i) {
    cin >> st;
    for (long long j = long long(0); j < long long(h); ++j) {
      if (st[j] == '#') first[i][j] = 1;
    }
  }
  for (long long i = long long(0); i < long long(w); ++i)
    for (long long j = long long(0); j < long long(h); ++j) {
      bfs(i, j);
    }
  cout << (ma - 1) << endl;
  return 0;
}
