#include <bits/stdc++.h>
using namespace std;
using P = pair<int, int>;
int h, w;
bool is_wall[20][20];
int dist(int sy, int sx) {
  int dx[] = {0, 0, 1, -1};
  int dy[] = {1, -1, 0, 0};
  vector<vector<int> > dist(h, vector<int>(w, -1));
  queue<P> que;
  que.push(make_pair(sy, sx));
  dist[sy][sx] = 0;
  int ld = 0;
  while (!que.empty()) {
    auto p = que.front();
    que.pop();
    int y = p.first;
    int x = p.second;
    for (int i = 0; i < 4; i++) {
      int nx = x + dx[i];
      int ny = y + dy[i];
      if (nx < 0 || nx >= w || ny < 0 || ny >= h) {
        continue;
      }
      if (dist[ny][nx] != -1 || is_wall[ny][nx]) {
        continue;
      }
      dist[ny][nx] = dist[y][x] + 1;
      ld = dist[ny][nx];
      que.push(make_pair(ny, nx));
    }
  }
  return ld;
}
int main() {
  cin >> h >> w;
  for (int y = 0; y < h; y++) {
    string s;
    cin >> s;
    for (int x = 0; x < w; x++) {
      is_wall[y][x] = (s.at(x) == '#');
    }
  }
  int max_d = 0;
  for (int y = 0; y < h; y++) {
    for (int x = 0; x < w; x++) {
      int cur = dist(y, x);
      if (max_d < cur) {
        max_d = cur;
      }
    }
  }
  cout << max_d << endl;
  return 0;
}
