#include <bits/stdc++.h>
using namespace std;
int h, w;
string s[101];
int main() {
  cin >> h >> w;
  for (int i = 1; i <= h; i++) {
    cin >> s[i];
    s[i] = '#' + s[i] + '#';
  }
  for (int i = 0; i <= w + 1; i++) {
    s[0] += '#';
    s[h + 1] += '#';
  }
  int dx[4] = {0, -1, 0, 1}, dy[4] = {1, 0, -1, 0};
  int ans = 0;
  for (int i = 1; i <= h; i++) {
    for (int j = 1; j <= w; j++) {
      bool used[55][55] = {0};
      queue<pair<int, pair<long long, long long>>> q;
      q.push(make_pair(0, pair<long long, long long>(i, j)));
      int cnt = 0;
      while (!q.empty()) {
        pair<int, pair<long long, long long>> fr = q.front();
        q.pop();
        pair<long long, long long> p = fr.second;
        cnt = fr.first;
        for (int i = 0; i < 4; i++) {
          int nx = dx[i] + p.first, ny = dy[i] + p.second;
          if (s[nx][ny] == '#') continue;
          if (used[nx][ny]) continue;
          used[nx][ny] = 1;
          q.push(make_pair(cnt + 1, pair<long long, long long>(nx, ny)));
        }
      }
      ans = max(ans, cnt);
    }
  }
  cout << ans << endl;
  return 0;
}
