#include <bits/stdc++.h>
using namespace std;
int mai = 0;
void solve() { return; }
void bfs(int x, int y, vector<string> s) {
  map<pair<int, int>, int> ma;
  int i, j, e;
  pair<int, int> aux;
  queue<pair<int, pair<int, int>>> q;
  q.push(make_pair(0, make_pair(x, y)));
  while (q.empty() == false) {
    i = q.front().second.first;
    j = q.front().second.second;
    e = q.front().first;
    aux = make_pair(i, j);
    if (ma[aux] != 0) {
      q.pop();
      continue;
    }
    q.pop();
    mai = max(e, mai);
    ma[aux]++;
    cout << "";
    if (s[i][j + 1] == '.' and ma[make_pair(i, j + 1)] == 0) {
      q.push(make_pair(e + 1, make_pair(i, j + 1)));
    }
    if (j != 0 and s[i][j - 1] == '.' and ma[make_pair(i, j - 1)] == 0) {
      q.push(make_pair(e + 1, make_pair(i, j - 1)));
    }
    if (s[i + 1][j] == '.' and ma[make_pair(i + 1, j)] == 0) {
      q.push(make_pair(e + 1, make_pair(i + 1, j)));
    }
    if (i != 0 and s[i - 1][j] == '.' and ma[make_pair(i - 1, j)] == 0) {
      q.push(make_pair(e + 1, make_pair(i - 1, j)));
    }
  }
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n, m;
  string s;
  cin >> n >> m;
  vector<string> v(n + 1);
  for (int i = 0; i < n; i++) {
    cin >> v[i];
    v[i].push_back('#');
  }
  for (int j = 0; j < m; j++) {
    v[n].push_back('#');
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      bfs(i, j, v);
    }
  }
  cout << mai << endl;
  return 0;
}
