#include <bits/stdc++.h>
using namespace std;
using ll = long long;
struct Node {
  int x, y, cnt;
  Node(int x = 0, int y = 0, int cnt = 0) : x(x), y(y), cnt(cnt){};
};
int h, w;
char m[30][30];
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
int bfs(int sx, int sy) {
  int ret = 0;
  queue<Node> que;
  bool vs[h][w];
  memset(vs, false, sizeof(vs));
  que.emplace(sx, sy, 0);
  while (!que.empty()) {
    auto p = que.front();
    que.pop();
    int x = p.x, y = p.y, cnt = p.cnt;
    ret = max(ret, cnt);
    for (int i = 0; i < 4; ++i) {
      int nx = x + dx[i], ny = y + dy[i];
      if (nx < 0 || ny < 0 || nx >= h || ny >= w || m[nx][ny] == '#' ||
          vs[nx][ny])
        continue;
      que.emplace(nx, ny, cnt + 1);
      vs[nx][ny] = true;
    }
  }
  return ret;
}
signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> h >> w;
  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j) {
      cin >> m[i][j];
    }
  }
  int ans = 0;
  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j) {
      if (m[i][j] == '#') continue;
      ans = max(ans, bfs(i, j));
    }
  }
  cout << ans << '\n';
  return (0);
}
