#include <bits/stdc++.h>
using namespace std;
const int NMAX = 20 + 1;
const int MMAX = 20 + 1;
int n, m;
char mp[NMAX][MMAX];
int ans[NMAX][MMAX];
struct q_node {
  int x, y, num;
};
int dx[4 + 1] = {0, 0, 1, 0, -1};
int dy[4 + 1] = {0, 1, 0, -1, 0};
void bfs(int x, int y) {
  int vis[NMAX][MMAX];
  memset(vis, 0, sizeof(vis));
  queue<q_node> q;
  q_node head;
  head.x = x, head.y = y, head.num = 0;
  q.push(head);
  while (!q.empty()) {
    q_node temp = q.front();
    for (int i = 1; i <= 4; i++) {
      q_node next;
      next.x = temp.x + dx[i];
      next.y = temp.y + dy[i];
      next.num = temp.num + 1;
      if (next.x <= n && next.x >= 1 && next.y <= m && next.y >= 1 &&
          !vis[next.x][next.y] && mp[next.x][next.y] == '.') {
        vis[next.x][next.y] = 1;
        q.push(next);
        ans[next.x][next.y] = max(ans[next.x][next.y], next.num);
      }
    }
    q.pop();
  }
}
int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) {
      cin >> mp[i][j];
    }
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++)
      if (mp[i][j] == '.') bfs(i, j);
  int res = 0;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) {
      res = max(res, ans[i][j]);
    }
  cout << res << endl;
}
