#include <bits/stdc++.h>
using namespace std;
long long mp[30][30];
long long dx[4] = {0, 0, 1, -1}, dy[4] = {1, -1, 0, 0};
long long n, m;
vector<string> vs;
pair<long long, long long> bfs(pair<long long, long long> st) {
  queue<long long> que;
  que.push(st.first);
  que.push(st.second);
  memset(mp, -1, sizeof(mp));
  mp[st.first][st.second] = 0;
  long long ma = -1000000000000000000;
  pair<long long, long long> ret;
  while (que.size()) {
    long long xx = que.front();
    que.pop();
    long long yy = que.front();
    que.pop();
    for (int i = 0; i < 4; i++) {
      long long sx = xx + dx[i];
      long long sy = yy + dy[i];
      if (sx < 0 || sx >= n || sy < 0 || sy >= m || vs[sx][sy] == '#') {
        continue;
      }
      if (mp[sx][sy] == -1) {
        que.push(sx);
        que.push(sy);
        mp[sx][sy] = mp[xx][yy] + 1;
        if (ma < mp[sx][sy]) {
          ma = mp[sx][sy];
          ret.first = sx, ret.second = sy;
        }
      }
    }
  }
  return ret;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  cerr.tie(nullptr);
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;
    vs.push_back(s);
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (vs[i][j] == '.') {
        pair<long long, long long> p = bfs(pair<long long, long long>(i, j));
        pair<long long, long long> e = bfs(p);
        cout << mp[e.first][e.second] << endl;
        return 0;
      }
    }
  }
  return 0;
}
