#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
const long long N = 100500;
const long long mod = 1e9 + 7;
using namespace std;
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << " : " << arg1 << " | ";
  __f(comma + 1, args...);
}
int alt[250][250];
int vis[250][250];
char grid[250][250];
int n, m;
void bfs(pair<int, int> u) {
  queue<pair<int, int>> q;
  vis[u.first][u.second] = true;
  q.push(u);
  while (!q.empty()) {
    pair<int, int> v = q.front();
    q.pop();
    if (v.first >= 1 and !vis[v.first - 1][v.second] and
        grid[v.first - 1][v.second] == '.') {
      vis[v.first - 1][v.second] = true;
      q.push({v.first - 1, v.second});
      alt[v.first - 1][v.second] = alt[v.first][v.second] + 1;
    }
    if (v.first <= n - 2 and !vis[v.first + 1][v.second] and
        grid[v.first + 1][v.second] == '.') {
      vis[v.first + 1][v.second] = true;
      q.push({v.first + 1, v.second});
      alt[v.first + 1][v.second] = alt[v.first][v.second] + 1;
    }
    if (v.second >= 1 and !vis[v.first][v.second - 1] and
        grid[v.first][v.second - 1] == '.') {
      vis[v.first][v.second - 1] = true;
      q.push({v.first, v.second - 1});
      alt[v.first][v.second - 1] = alt[v.first][v.second] + 1;
    }
    if (v.second <= m - 2 and !vis[v.first][v.second + 1] and
        grid[v.first][v.second + 1] == '.') {
      vis[v.first][v.second + 1] = true;
      q.push({v.first, v.second + 1});
      alt[v.first][v.second + 1] = alt[v.first][v.second] + 1;
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n >> m;
  pair<int, int> p;
  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;
    for (int j = 0; j < m; j++) {
      grid[i][j] = s[j];
      if (s[j] == '.') p = {i, j};
    }
  }
  bfs(p);
  int maxi = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (alt[i][j] > maxi) {
        maxi = alt[i][j];
        p = {i, j};
      }
    }
  }
  for (int i = 0; i < 250; i++) {
    for (int j = 0; j < 250; j++) {
      alt[i][j] = 0;
      vis[i][j] = false;
    }
  }
  bfs(p);
  maxi = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      maxi = max(maxi, alt[i][j]);
    }
  }
  cout << maxi << endl;
  return 0;
}
