#include <bits/stdc++.h>
using namespace std;
long long MOD = 1000000007;
long long INF = 214748364700000000;
double EPS = 1e-12;
double PI = 3.141592653589793238;
template <typename T>
void remove(std::vector<T>& vector, unsigned int index) {
  vector.erase(vector.begin() + index);
}
using Graph = vector<vector<pair<long long, long long>>>;
long long H, W;
char field[30][30];
long long d[30][30];
long long dy[4]{-1, 0, 1, 0};
long long dx[4]{0, -1, 0, 1};
long long bfs(long long sy, long long sx, long long gy, long long gx) {
  for (long long i = (long long)0; i < (long long)30; i++)
    for (long long j = (long long)0; j < (long long)30; j++) d[i][j] = INF;
  queue<pair<long long, long long>> Q;
  d[sy][sx] = 0;
  Q.emplace(sy, sx);
  while (Q.size()) {
    long long y, x;
    tie(y, x) = Q.front();
    Q.pop();
    if (y == gy && x == gx) {
      break;
    }
    for (long long i = (long long)0; i < (long long)4; i++) {
      long long ny = dy[i] + y, nx = dx[i] + x;
      if (0 <= ny && ny < H && 0 <= nx && nx < W) {
        if (d[ny][nx] == INF && field[ny][nx] != '#') {
          d[ny][nx] = d[y][x] + 1;
          Q.emplace(ny, nx);
        }
      }
    }
  }
  return d[gy][gx];
}
int main() {
  cin >> H >> W;
  for (long long i = (long long)0; i < (long long)H; i++)
    for (long long j = (long long)0; j < (long long)W; j++) {
      cin >> field[i][j];
    }
  long long ans = -1;
  for (long long i = (long long)0; i < (long long)H; i++)
    for (long long j = (long long)0; j < (long long)W; j++)
      for (long long k = (long long)0; k < (long long)H; k++)
        for (long long l = (long long)0; l < (long long)W; l++) {
          long long D = bfs(i, j, k, l);
          if (D != INF) {
            ans = max(ans, D);
          }
        }
  cout << ans << endl;
}
