#include <bits/stdc++.h>
using namespace std;
int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
int dy[8] = {0, 1, 0, -1, 1, -1, 1, -1};
void print(bool f) { cout << (f ? "Yes" : "No") << endl; }
void Print(bool f) { cout << (f ? "YES" : "NO") << endl; }
long long int h, w;
long long int bfs(vector<string> path, long long int y, long long int x) {
  queue<pair<long long int, long long int>> q;
  q.push(make_pair(y, x));
  vector<vector<long long int>> pass(h, vector<long long int>(w, 0));
  vector<vector<long long int>> cnt(h, vector<long long int>(w, 0));
  pass[y][x] = 1;
  cnt[y][x] = 0;
  long long int m = 0;
  while (!q.empty()) {
    pair<long long int, long long int> p = q.front();
    q.pop();
    for (long long int i = 0; i < 4; i++) {
      long long int ny = p.first + dy[i], nx = p.second + dx[i];
      if (ny < 0 || ny >= h || nx < 0 || nx >= w) continue;
      if (!pass[ny][nx] && path[ny][nx] == '.') {
        q.push(make_pair(ny, nx));
        pass[ny][nx] = 1;
        cnt[ny][nx] = cnt[p.first][p.second] + 1;
        m = max(m, cnt[ny][nx]);
      }
    }
  }
  return m;
}
int main(void) {
  cin >> h >> w;
  vector<string> s(h);
  for (long long int i = 0; i < h; i++) cin >> s[i];
  long long int ans = 0;
  for (long long int i = 0; i < h; i++) {
    for (long long int j = 0; j < w; j++) ans = max(ans, bfs(s, i, j));
  }
  cout << ans << endl;
}
