#include <bits/stdc++.h>
using namespace std;
long long a, b, c, d, e, zx, xc, man[21][21];
deque<pair<long long, long long> > de;
char f[39][39];
int bo[21][21];
vector<pair<long long, long long> > v[21][21];
string s;
bool cs(int q, int w) {
  if (q > a || w > b || q < 1 || w < 1) return 0;
  if (f[q][w] == '#') return 0;
  return 1;
}
void fl(int q, int w, int qw, int we) { v[q][w].push_back(make_pair(qw, we)); }
void dfs(int q, int w, int r) {
  if (cs(q + 1, w)) {
    fl(q, w, q + 1, w);
  }
  if (cs(q, w + 1)) {
    fl(q, w, q, w + 1);
  }
  if (cs(q - 1, w)) {
    fl(q, w, q - 1, w);
  }
  if (cs(q, w - 1)) {
    fl(q, w, q, w - 1);
  }
}
int main() {
  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  cin >> a >> b;
  for (c = 1; c <= a; c++) {
    cin >> s;
    for (d = 1; d <= b; d++) f[c][d] = s[d - 1];
  }
  for (c = a; c >= 1; c--) {
    for (d = b; d >= 1; d--) {
      dfs(c, d, 0);
    }
  }
  int cnt = 0;
  for (c = 1; c <= a; c++) {
    for (d = 1; d <= b; d++) {
      cnt++;
      bo[c][d] = cnt;
      man[c][d] = 0;
      de.push_back(make_pair(c, d));
      while (de.size() > 0) {
        zx = de.front().first;
        xc = de.front().second;
        de.pop_front();
        for (vector<pair<long long, long long> >::iterator it =
                 v[zx][xc].begin();
             it != v[zx][xc].end(); it++) {
          if (bo[(*it).first][(*it).second] == cnt) continue;
          bo[(*it).first][(*it).second] = cnt;
          man[(*it).first][(*it).second] = man[zx][xc] + 1;
          if (e < man[zx][xc] + 1) e = man[zx][xc] + 1;
          de.push_back(make_pair((*it).first, (*it).second));
        }
      }
    }
  }
  cout << e;
  return 0;
}
