#include <bits/stdc++.h>
using namespace std;
vector<int> a[1000];
int hei[1000], vis[1000], mx = 0;
void bfs(int root) {
  queue<int> q;
  q.push(root);
  vis[root] = 1;
  while (q.size()) {
    int f = q.front();
    q.pop();
    for (auto i : a[f]) {
      if (!vis[i]) {
        q.push(i);
        vis[i] = 1;
        hei[i] = hei[f] + 1;
        if (hei[i] > hei[mx]) mx = i;
      }
    }
  }
}
void add(int u, int v) {
  a[u].push_back(v);
  a[v].push_back(u);
}
int main() {
  ios_base::sync_with_stdio(0);
  cout.tie(0);
  cin.tie(0);
  int h, w;
  cin >> h >> w;
  char g[h][w];
  int root = -1;
  for (int i = 0; i < h; ++i)
    for (int j = 0; j < w; ++j) {
      cin >> g[i][j];
      if (g[i][j] == '.') root = i * w + j;
    }
  for (int i = 0; i < h - 1; ++i)
    for (int j = 0; j < w; ++j)
      if (g[i][j] == '.' && g[i + 1][j] == '.') add(i * w + j, (i + 1) * w + j);
  for (int i = 0; i < h; ++i)
    for (int j = 0; j < w - 1; ++j)
      if (g[i][j] == '.' && g[i][j + 1] == '.') add(i * w + j, i * w + j + 1);
  if (root == -1) {
    cout << 0;
  } else {
    memset(hei, 0, sizeof hei);
    memset(vis, 0, sizeof vis);
    bfs(root);
    memset(hei, 0, sizeof hei);
    memset(vis, 0, sizeof vis);
    bfs(mx);
    cout << hei[mx];
  }
}
