#include <bits/stdc++.h>
const int inf = (1 << 30);
const int mod = 1000000007;
using ll = long long;
using namespace std;
char cm[30][30];
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
int mm[30][30];
void init() {
  for (int i = 0; i < 25; ++i) {
    for (int j = 0; j < 25; ++j) {
      mm[i][j] = 0;
    }
  }
}
int main() {
  int h, w;
  cin >> h >> w;
  for (int i = 0; i < 25; ++i) {
    for (int j = 0; j < 25; ++j) {
      cm[i][j] = '#';
    }
  }
  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j) {
      char c;
      cin >> c;
      cm[i + 1][j + 1] = c;
    }
  }
  int ans = 0;
  for (int si = 1; si < h + 1; ++si) {
    for (int sj = 1; sj < w + 1; ++sj) {
      init();
      queue<int> q;
      q.push((si)*100 + (sj));
      int cnt = 0;
      while (!q.empty()) {
        int a = q.front();
        q.pop();
        int y = a % 100, x = a / 100;
        for (int i = 0; i < 4; ++i) {
          if (cm[x + dx[i]][y + dy[i]] == '#' || mm[x + dx[i]][y + dy[i]] > 0 ||
              (x + dx[i] == si && y + dy[i] == sj))
            continue;
          ans = max(ans, mm[x + dx[i]][y + dy[i]] = mm[x][y] + 1);
          q.push(100 * (x + dx[i]) + y + dy[i]);
        }
      }
    }
  }
  cout << ans << endl;
}
