#include <bits/stdc++.h>
using namespace std;
const int MAXH = 21;
const int MAXW = 21;
int mp[MAXH][MAXW], vis[MAXH][MAXW];
struct q_node {
  int x, y, num;
};
int dx[4 + 1] = {0, 1, 0, -1};
int dy[4 + 1] = {-1, 0, 1, 0};
int h, w;
int bfs(int x, int y) {
  memset(vis, 0, sizeof(vis));
  queue<q_node> q;
  q_node head;
  head.x = x, head.y = y, head.num = 0;
  q.push(head);
  int maxv = 0;
  int xx = 0, yy = 0;
  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 <= h && next.x >= 1 && next.y <= w && next.y >= 1 &&
          !vis[next.x][next.y] && mp[next.x][next.y] == 0) {
        vis[next.x][next.y] = 1;
        q.push(next);
        maxv = max(maxv, next.num);
        xx = next.x;
        yy = next.y;
      }
    }
    q.pop();
  }
  cout << "from x=" << x << ",y=" << y << ":" << maxv << " to x=" << xx
       << " y=" << yy << endl;
  return maxv;
}
int main() {
  cin >> h >> w;
  for (int i = 1; i <= h; i++)
    for (int j = 1; j <= w; j++) {
      char x;
      cin >> x;
      if (x == '.')
        mp[i][j] = 0;
      else if (x == '#')
        mp[i][j] = 1;
    }
  int ans = 0;
  for (int i = 1; i <= h; i++)
    for (int j = 1; j <= w; j++) {
      if (mp[i][j] == 0) ans = max(ans, bfs(i, j));
    }
  cout << ans << endl;
}
