#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
using vi = vector<ll>;
using vvi = vector<vi>;
int H, W;
vvi G;
bool valid(int i, int j, int i2, int j2) {
  if (i < i2) return true;
  if (i == i2) return j < j2;
  return false;
}
bool ins(int i, int j) {
  return i >= 0 and j >= 0 and i < H and j < W and G[i][j];
}
int bfs(int i, int j, int i2, int j2) {
  vvi vis(H, vi(W, 0));
  queue<vi> q;
  q.push({i, j, 0});
  while (not q.empty()) {
    vi u = q.front();
    q.pop();
    if (u[0] == i2 and u[1] == j2) return u[2];
    if (not vis[u[0]][u[1]]) {
      vis[u[0]][u[1]] = 1;
      if (ins(u[0] + 1, u[1])) q.push({u[0] + 1, u[1], u[2] + 1});
      if (ins(u[0], u[1] - 1)) q.push({u[0], u[1] - 1, u[2] + 1});
      if (ins(u[0] - 1, u[1])) q.push({u[0] - 1, u[1], u[2] + 1});
      if (ins(u[0], u[1] + 1)) q.push({u[0], u[1] + 1, u[2] + 1});
    }
  }
  return -1;
}
int main() {
  cin >> H >> W;
  G = vvi(H, vi(W, 0));
  for (int i = 0; i < H; i++)
    for (int j = 0; j < W; j++) {
      char c;
      cin >> c;
      if (c == '.') G[i][j] = 1;
    }
  int maxim = 0;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      for (int i2 = 0; i2 < H; i2++) {
        for (int j2 = 0; j2 < W; j2++) {
          int d = bfs(i, j, i2, j2);
          if (d > maxim) maxim = d;
        }
      }
    }
  }
  cout << maxim << endl;
}
