#include <bits/stdc++.h>
using namespace std;
int H, W;
char maze[20][20 + 1];
int d[20][20];
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
int ans = INT_MIN;
void bfs(int sx, int sy) {
  queue<pair<int, int> > que;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      d[i][j] = -1;
    }
  }
  que.push(pair<int, int>(sx, sy));
  d[sy][sx] = 0;
  while (que.size()) {
    pair<int, int> p = que.front();
    que.pop();
    for (int i = 0; i < 4; i++) {
      int nx = p.first + dx[i], ny = p.second + dy[i];
      if (0 <= nx && nx < W && 0 <= ny && ny < H && maze[ny][nx] != '#' &&
          d[ny][nx] == -1) {
        que.push(pair<int, int>(nx, ny));
        d[ny][nx] = d[p.second][p.first] + 1;
      }
    }
  }
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      ans = max(d[i][j], ans);
    }
  }
}
int main() {
  cin >> H >> W;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      cin >> maze[i][j];
    }
  }
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      bfs(j, i);
    }
  }
  cout << ans << endl;
  return 0;
}
