#include <bits/stdc++.h>
using namespace std;
char s[29][29];
int vis[29][29];
int dir[4][2] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};
int xx, yy;
struct node {
  int x, y, cnt;
};
int bfs(int x, int y) {
  int ans = 0;
  memset(vis, 0, sizeof(vis));
  node a, b;
  queue<node> q;
  a.x = x, a.y = y, a.cnt = 0;
  vis[x][y] = 1;
  q.push(a);
  while (!q.empty()) {
    a = q.front();
    q.pop();
    for (int i = 0; i < 4; i++) {
      b.x = a.x + dir[i][0];
      b.y = a.y + dir[i][1];
      b.cnt = a.cnt + 1;
      if (b.x < 0 || b.x >= xx || b.y < 0 || b.y >= yy || vis[b.x][b.y] ||
          s[b.x][b.y] == '#')
        continue;
      vis[b.x][b.y] = 1;
      ans = max(ans, b.cnt);
      q.push(b);
    }
  }
  return ans;
}
int main() {
  scanf("%d%d", &xx, &yy);
  for (int i = 0; i < xx; i++) {
    for (int j = 0; j < yy; j++) {
      cin >> s[i][j];
    }
  }
  int ma = 0;
  for (int i = 0; i < xx; i++) {
    for (int j = 0; j < yy; j++) {
      ma = max(ma, bfs(i, j));
    }
  }
  cout << ma << endl;
  return 0;
}
