#include <bits/stdc++.h>
using namespace std;
const int MAXN = 25;
const int di[] = {-1, 1, 0, 0};
const int dj[] = {0, 0, -1, 1};
int n, m;
char c[MAXN][MAXN];
bool used[MAXN][MAXN];
int dist[MAXN][MAXN];
queue<pair<int, int> > q;
int ans = 0;
int main() {
  scanf("%d %d\n", &n, &m);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      scanf("%c", &c[i][j]);
    }
    scanf("\n");
  }
  for (int si = 0; si < n; si++) {
    for (int sj = 0; sj < m; sj++) {
      memset(used, false, sizeof(used));
      memset(dist, 0, sizeof(dist));
      used[si][sj] = true;
      q.push({si, sj});
      while (!q.empty()) {
        pair<int, int> p = q.front();
        q.pop();
        for (int k = 0; k < 4; k++) {
          int ci = p.first + di[k];
          int cj = p.second + dj[k];
          if (ci < 0 || ci >= n || cj < 0 || cj >= m || c[ci][cj] == '#' ||
              used[ci][cj]) {
            continue;
          }
          used[ci][cj] = true;
          dist[ci][cj] = dist[p.first][p.second] + 1;
          q.push({ci, cj});
        }
      }
      for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
          ans = max(ans, dist[i][j]);
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}
