#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
int n, m;
int v[22][22];
char maze[22][22];
int res = 0;
bool check(int x, int y) {
  if (maze[x][y] == '.' && !v[x][y]) return 1;
  return 0;
}
void bfs(int now) {
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= m; ++j) v[i][j] = 0;
  queue<pair<int, int> > q;
  q.push(make_pair(now, 0));
  while (!q.empty()) {
    int now_ = q.front().first, step = q.front().second;
    q.pop();
    res = max(res, step);
    int x, y;
    x = now_ / 100, y = now_ % 100;
    v[x][y] = 1;
    if (x != 1) {
      if (check(x - 1, y)) {
        q.push(make_pair((x - 1) * 100 + y, step + 1));
      }
    }
    if (x != n) {
      if (check(x + 1, y)) {
        q.push(make_pair((x + 1) * 100 + y, step + 1));
      }
    }
    if (y != 1) {
      if (check(x, y - 1)) {
        q.push(make_pair((x)*100 + y - 1, step + 1));
      }
    }
    if (y != m) {
      if (check(x, y + 1)) {
        q.push(make_pair((x)*100 + y + 1, step + 1));
      }
    }
  }
}
int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= m; ++j) cin >> maze[i][j];
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= m; ++j) {
      if (maze[i][j] == '.') bfs(i * 100 + j);
    }
  cout << res;
  return 0;
}
