#include <bits/stdc++.h>
using namespace std;
int n, m, dis[22][22], ans;
char mp[22][22];
inline bool check(register int x, register int y) {
  if (x < 1 || x > n || y < 1 || y > m) return 0;
  if (mp[x][y] == '#') return 0;
  if (dis[x][y]) return 0;
  return 1;
}
queue<int> q;
inline void bfs(register int x, register int y) {
  q.push(x);
  q.push(y);
  while (!q.empty()) {
    x = q.front();
    q.pop();
    y = q.front();
    q.pop();
    if (check(x + 1, y))
      dis[x + 1][y] = dis[x][y] + 1, q.push(x + 1), q.push(y);
    if (check(x - 1, y))
      dis[x - 1][y] = dis[x][y] + 1, q.push(x - 1), q.push(y);
    if (check(x, y + 1))
      dis[x][y + 1] = dis[x][y] + 1, q.push(x), q.push(y + 1);
    if (check(x, y - 1))
      dis[x][y - 1] = dis[x][y] + 1, q.push(x), q.push(y - 1);
  }
}
signed main() {
  scanf("%d%d", &n, &m);
  for (register int i = 1; i <= n; ++i) scanf("%s", mp[i] + 1);
  for (register int i = 1; i <= n; ++i) {
    for (register int j = 1; j <= m; ++j) {
      if (mp[i][j] == '.') {
        memset(dis, 0, sizeof(dis));
        dis[i][j] = 1;
        bfs(i, j);
        for (register int ii = 1; ii <= n; ++ii) {
          for (register int jj = 1; jj <= m; ++jj) {
            cout << ans << endl;
            ans = max(ans, dis[ii][jj]);
          }
        }
      }
    }
  }
  cout << ans - 1;
}
