#include <bits/stdc++.h>
using namespace std;
int dx[] = {0, 1, 0, -1};
int dy[] = {-1, 0, 1, 0};
string s[110];
int solve(int x, int y, int n, int m) {
  queue<pair<int, int> > q;
  int xx, yy;
  q.push({x, y});
  int dist[n + 10][m + 10];
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      dist[i][j] = 1e6;
    }
  }
  dist[x][y] = 0;
  while (!q.empty()) {
    pair<int, int> u;
    u = q.front();
    q.pop();
    for (int i = 0; i < 4; i++) {
      xx = u.first + dx[i];
      yy = u.second + dy[i];
      if (xx < 0 || yy < 0 || xx >= n || yy >= m ||
          dist[xx][yy] <= dist[u.first][u.second] + 1 || s[xx][yy] == '#')
        continue;
      dist[xx][yy] = dist[u.first][u.second] + 1;
      q.push({xx, yy});
    }
  }
  int d = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (s[i][j] != '#') d = max(d, dist[i][j]);
    }
  }
  return d;
}
int main() {
  int h, w, i, j, k, l, m, n;
  cin >> h >> w;
  int dp[h + 10][w + 10];
  for (i = 0; i < h; i++) cin >> s[i];
  int ans = 0;
  for (i = 0; i < h; i++) {
    for (j = 0; j < w; j++) {
      ans = max(ans, solve(i, j, h, w));
    }
  }
  cout << ans << '\n';
}
