#include <bits/stdc++.h>
using namespace std;
int h, w, maxi, dist[21][21];
bool wall[21][21];
int cx[] = {0, 0, 1, -1};
int cy[] = {1, -1, 0, 0};
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> h >> w;
  for (int i = 1; i <= h; i++) {
    for (int j = 1; j <= w; j++) {
      char x;
      cin >> x;
      if (x == '#') wall[i][j] = true;
    }
  }
  for (int i = 1; i <= h; i++) {
    for (int j = 1; j <= w; j++) {
      memset(dist, -1, sizeof(dist));
      queue<pair<int, int> > q;
      dist[i][j] = 0;
      q.push(make_pair(i, j));
      while (!q.empty()) {
        pair<int, int> cur = q.front();
        q.pop();
        for (int k = 0; k < 4; k++) {
          int dx = cur.first + cx[k];
          int dy = cur.second + cy[k];
          if (dx < 1 || dx > h || dy < 1 || dy > w) continue;
          if (wall[dx][dy]) continue;
          if (dist[dx][dy] != -1) continue;
          dist[dx][dy] = dist[cur.first][cur.second] + 1;
          q.push(make_pair(dx, dy));
        }
      }
      for (int a = 1; a <= h; a++) {
        for (int b = 1; b <= w; b++) {
          maxi = max(maxi, dist[a][b]);
        }
      }
    }
  }
  cout << maxi;
}
