#include <bits/stdc++.h>
using namespace std;
long long exp(long long x, long long y, long long p) {
  long long res = 1;
  while (y) {
    if (y % 2) res = (res * x % p) % p;
    x = (x * x) % p;
    y /= 2;
  }
  return res;
}
long long expm(long long x, long long y) {
  long long res = 1;
  while (y) {
    if (y % 2) res = (res * x % ((long long)1e9 + 7)) % ((long long)1e9 + 7);
    x = (x * x) % ((long long)1e9 + 7);
    y /= 2;
  }
  return res;
}
long long adj[20][20];
long long vis[20][20];
long long dis[20][20];
long long dx[] = {-1, 0, 1, 0};
long long dy[] = {0, -1, 0, 1};
long long h, w;
bool check(long long x, long long y) {
  if (x < 0 || x >= h || y < 0 || y >= w || adj[x][y] == 0) return 0;
  return 1;
}
long long bfs(long long sx, long long sy) {
  queue<pair<long long, long long>> q;
  q.push({sx, sy});
  memset(vis, 0, sizeof(vis));
  memset(dis, 0, sizeof(dis));
  dis[sx][sy] = 0;
  long long maxDis = -2;
  while (q.size()) {
    pair<long long, long long> u = q.front();
    q.pop();
    vis[u.first][u.second] = 1;
    for (long long i = 0; i < 4; i++) {
      long long nx = u.first + dx[i];
      long long ny = u.second + dy[i];
      if (check(nx, ny) && vis[nx][ny] != 1) {
        dis[nx][ny] = dis[u.first][u.second] + 1;
        maxDis = max(maxDis, dis[nx][ny]);
        q.push({nx, ny});
      }
    }
  }
  return maxDis;
}
signed main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  {
    cin >> h >> w;
    char ch;
    for (long long i = 0; i < h; i++) {
      for (long long j = 0; j < w; j++) {
        cin >> ch;
        if (ch == '.') adj[i][j] = 1;
      }
    }
    long long mx = -1;
    for (long long i = 0; i < h; i++)
      for (long long j = 0; j < w; j++)
        if (adj[i][j] == 1) mx = max(mx, bfs(i, j));
    cout << mx;
  }
  return 0;
}
