#include <bits/stdc++.h>
using namespace std;
unsigned long long int H, W;
unsigned long long int INF = 10000000;
unsigned long long int enc(unsigned long long int h, unsigned long long int w) {
  return h * W + w;
}
int floydWarshall(vector<vector<unsigned long long int>> graph) {
  int V = H * W;
  vector<vector<int>> dist(V, vector<int>(V));
  int i, j, k;
  for (i = 0; i < V; i++)
    for (j = 0; j < V; j++) dist[i][j] = graph[i][j];
  for (k = 0; k < V; k++) {
    for (i = 0; i < V; i++) {
      for (j = 0; j < V; j++) {
        if (dist[i][k] + dist[k][j] < dist[i][j])
          dist[i][j] = dist[i][k] + dist[k][j];
      }
    }
  }
  int ret = -1;
  for (i = 0; i < V; i++)
    for (j = 0; j < V; j++) {
      if (i == j) {
        continue;
      }
      if (dist[i][j] > ret && dist[i][j] < INF) {
        ret = dist[i][j];
      }
    }
  return ret;
}
int main() {
  cin >> H >> W;
  vector<vector<bool>> S(H, vector<bool>(W, false));
  for (int i = 0; i < H; ++i) {
    string p;
    cin >> p;
    for (int j = 0; j < W; ++j) {
      if (p[j] == '#') {
        S[i][j] = true;
      }
    }
  }
  vector<vector<unsigned long long int>> G(
      H * W, vector<unsigned long long int>(H * W, INF));
  for (int i = 0; i < H; ++i) {
    for (int j = 0; j < W; ++j) {
      if (S[i][j]) {
        continue;
      }
      if (0 < i && !S[i - 1][j]) {
        G[enc(i, j)][enc(i - 1, j)] = 1;
      }
      if (i < H - 1 && !S[i + 1][j]) {
        G[enc(i, j)][enc(i + 1, j)] = 1;
      }
      if (0 < j && !S[i][j - 1]) {
        G[enc(i, j)][enc(i, j - 1)] = 1;
      }
      if (j < W - 1 && !S[i][j + 1]) {
        G[enc(i, j)][enc(i, j + 1)] = 1;
      }
    }
  }
  int m = floydWarshall(G);
  cout << m << endl;
}
