#include <bits/stdc++.h>
using namespace std;
unsigned long long N, M;
vector<unsigned long long> a;
int H, W;
int maze[20][20];
bool bound(int y, int x) { return !(x < 0 || x > W || y < 0 || y > H); }
int calc(int sy, int sx) {
  int m[20][20], score[20][20];
  for (int y = 0; y < H; y++) {
    for (int x = 0; x < W; x++) {
      score[y][x] = 10000000;
      m[y][x] = maze[y][x];
    }
  }
  int maxd = 0;
  queue<pair<int, pair<int, int> > > q;
  q.push(make_pair(0, make_pair(sy, sx)));
  score[sy][sx] = 0;
  const int dx[] = {0, 1, 0, -1};
  const int dy[] = {1, 0, -1, 0};
  while (!q.empty()) {
    pair<int, pair<int, int> > c = q.front();
    q.pop();
    int d = c.first;
    int cy = c.second.first;
    int cx = c.second.second;
    if (score[cy][cx] < d) {
      continue;
    }
    for (int i = 0; i < 4; i++) {
      int ny = cy + dy[i];
      int nx = cx + dx[i];
      if (bound(ny, nx) && m[ny][nx] == 0 && score[ny][nx] == 10000000) {
        score[ny][nx] = d + 1;
        q.push(make_pair(d + 1, make_pair(ny, nx)));
      }
    }
  }
  for (int y = 0; y < H; y++) {
    for (int x = 0; x < W; x++) {
      if (m[y][x] == 0) {
        maxd = max(maxd, score[y][x]);
      }
    }
  }
  return maxd;
}
int main() {
  cin >> H >> W;
  for (int y = 0; y < H; y++) {
    string s;
    cin >> s;
    for (int x = 0; x < W; x++) {
      maze[y][x] = s[x] == '.' ? 0 : 1;
    }
  }
  int ans = 0;
  for (int y = 0; y < H; y++) {
    for (int x = 0; x < W; x++) {
      if (maze[y][x] == 0) {
        ans = max(ans, calc(y, x));
      }
    }
  }
  cout << ans << endl;
  return 0;
}
