#include <bits/stdc++.h>
const int mod = 1000000007;
using namespace std;
int h, w;
char map[24][24];
char used[24][24];
int FindRode(int t, int l) {
  if (!map[t][l]) return -1;
  memset(used, 0, sizeof(used));
  queue<int> q;
  int pos = (t << 10) + (l << 5), f = 0, nf, nt, nl;
  q.push(pos);
  used[t][l] = 1;
  while (!q.empty()) {
    pos = q.front();
    q.pop();
    nt = pos >> 10;
    nl = (pos >> 5) % 32;
    nf = pos % 32;
    if (nf > f) f = nf;
    nf++;
    if (map[nt - 1][nl] && !used[nt - 1][nl]) {
      pos = ((nt - 1) << 10) + (nl << 5) + nf;
      q.push(pos);
      used[nt - 1][nl] = 1;
    }
    if (map[nt + 1][nl] && !used[nt + 1][nl]) {
      pos = ((nt + 1) << 10) + (nl << 5) + nf;
      q.push(pos);
      used[nt + 1][nl] = 1;
    }
    if (map[nt][nl - 1] && !used[nt][nl - 1]) {
      pos = (nt << 10) + ((nl - 1) << 5) + nf;
      q.push(pos);
      used[nt][nl - 1] = 1;
    }
    if (map[nt][nl + 1] && !used[nt][nl + 1]) {
      pos = (nt << 10) + ((nl + 1) << 5) + nf;
      q.push(pos);
      used[nt][nl + 1] = 1;
    }
  }
  return f;
}
int main(void) {
  ios::sync_with_stdio(false);
  cin >> h >> w;
  memset(map[0], 0, sizeof(map[0]));
  for (int nh = 1; nh <= h; nh++) {
    map[nh][0] = 0;
    for (int nw = 1; nw <= w; nw++) {
      char c;
      cin >> c;
      if (c == '.')
        map[nh][nw] = 1;
      else
        map[nh][nw] = 0;
    }
    map[nh][w + 1] = 0;
  }
  memset(map[h + 1], 0, sizeof(map[0]));
  int max = 0;
  for (int t = 1; t <= h; t++) {
    for (int l = 1; l <= w; l++) {
      int tmp = FindRode(t, l);
      if (tmp > max) max = tmp;
    }
  }
  cout << max << endl;
  return 0;
}
