#include <bits/stdc++.h>
using namespace std;
int search(int sx, int sy);
int h, w;
char mp[21][21];
int dx[4] = {0, 1, 0, -1};
int dy[4] = {-1, 0, 1, 0};
int main() {
  int ans = 0;
  cin >> h >> w;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      cin >> mp[i][j];
    }
  }
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      ans = max(ans, search(j, i));
    }
  }
  cout << ans << endl;
  return (0);
}
int search(int sx, int sy) {
  int mx = 0;
  int d[21][21];
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      d[i][j] = 1000000009;
    }
  }
  queue<pair<int, int> > que;
  que.push(pair<int, int>(sx, sy));
  d[sy][sx] = 0;
  while (!que.empty()) {
    pair<int, int> p = que.front();
    que.pop();
    int x = p.first;
    int y = p.second;
    for (int i = 0; i < 4; i++) {
      int nx = x + dx[i];
      int ny = y + dy[i];
      if (0 <= nx && nx < w && 0 <= ny && ny < h && mp[ny][nx] != '#' &&
          d[ny][nx] == 1000000009) {
        d[ny][nx] = d[y][x] + 1;
        mx = max(mx, d[ny][nx]);
        que.push(pair<int, int>(nx, ny));
      }
    }
  }
  return mx;
}
