#include <bits/stdc++.h>
using namespace std;
vector<int> adj[500];
bool color[500];
int d[500];
int bfs(int start, int size) {
  for (int i = 0; i < size; i++) {
    color[i] = false;
    d[i] = -1;
  }
  queue<int> bfsQueue;
  bfsQueue.push(start);
  d[start] = 0;
  while (bfsQueue.size() > 0) {
    int u = bfsQueue.front();
    bfsQueue.pop();
    for (int i = 0; i < adj[u].size(); i++) {
      int v = adj[u][i];
      if (!color[v]) {
        color[v] = true;
        d[v] = d[u] + 1;
        bfsQueue.push(v);
      }
    }
  }
  int maxD = -1;
  int maxDid = -1;
  for (int i = 0; i < size; i++) {
    if (d[i] > maxD) {
      maxD = d[i];
      maxDid = i;
    }
  }
  return maxDid;
}
int main() {
  int H, W;
  cin >> H >> W;
  string S[H];
  for (int i = 0; i < H; i++) {
    cin >> S[i];
  }
  int firstV = -1;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      int v = i * W + j;
      if (S[i][j] == '.') {
        if (firstV == -1) {
          firstV = v;
        }
        if (i - 1 >= 0 && S[i - 1][j] == '.') {
          adj[v].push_back((i - 1) * W + j);
        }
        if (i + 1 < H && S[i + 1][j] == '.') {
          adj[v].push_back((i + 1) * W + j);
        }
        if (j - 1 >= 0 && S[i][j - 1] == '.') {
          adj[v].push_back(i * W + j - 1);
        }
        if (j + 1 < W && S[i][j + 1] == '.') {
          adj[v].push_back(i * W + j + 1);
        }
      }
    }
  }
  int ans = -1;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      int v = i * W + j;
      if (S[i][j] == '.') {
        int a = bfs(v, H * W);
        if (ans == -1 || ans < d[a]) {
          ans = d[a];
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}
