#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
const long long MOD = 1e9 + 7;
const long long INF = 1LL << 60;
int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};
long long H, W;
long long bfs(int h, int w, string fi[25]) {
  int d[25][25];
  for (int i = 0; i < 25; i++)
    for (int j = 0; j < 25; j++) d[i][j] = -1;
  d[h][w] = 0;
  queue<pair<int, int>> qu;
  qu.push(make_pair(h, w));
  while (!qu.empty()) {
    pair<int, int> u = qu.front();
    qu.pop();
    fi[u.first][u.second] = '#';
    for (int i = 0; i < 4; i++) {
      int y = u.first + dy[i], x = u.second + dx[i];
      if (y < 0 || y >= H || x < 0 || x >= W) continue;
      if (fi[y][x] == '#') continue;
      d[y][x] = d[u.first][u.second] + 1;
      fi[y][x] = '#';
      qu.push(make_pair(y, x));
    }
  }
  int res = -1;
  for (int i = 0; i < H; i++)
    for (int j = 0; j < W; j++) res = max(res, d[i][j]);
  return res;
}
int main() {
  string field[25];
  cin >> H >> W;
  for (int i = 0; i < H; i++) {
    cin >> field[i];
  }
  long long ans = -1;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      string fie[25];
      for (int i = 0; i < H; i++) fie[i] = field[i];
      ans = max(ans, bfs(i, j, fie));
    }
  }
  cout << ans << endl;
  return 0;
}
