#include <bits/stdc++.h>
using namespace std;
const int INF = 1000000007;
int H, W;
vector<vector<char>> G(20, vector<char>(20));
vector<pair<int, int>> direction = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};
int bfs(pair<int, int> p, pair<int, int> &q) {
  if (G[p.first][p.second] == '#') return 0;
  vector<vector<int>> dist(20, vector<int>(20, -1));
  int ans = 0;
  queue<pair<int, int>> que;
  que.push(p);
  dist[p.first][p.second] = 0;
  while (!que.empty()) {
    pair<int, int> v = que.front();
    que.pop();
    for (pair<int, int> d : direction) {
      pair<int, int> v2(v.first + d.first, v.second + d.second);
      if (v2.first < 0 || v2.first >= H || v2.second < 0 || v2.second >= W ||
          G[v2.first][v2.second] == '#')
        continue;
      if (dist[v2.first][v2.second] != -1) continue;
      dist[v2.first][v2.second] = dist[v.first][v.second] + 1;
      if (ans < dist[v2.first][v2.second]) {
        q.first = v2.first;
        q.second = v2.second;
        ans = dist[v2.first][v2.second];
      }
      que.push(v2);
    }
  }
  return ans;
}
int main() {
  cin >> H >> W;
  pair<int, int> p0;
  for (int i = 0; i < (int)(H); i++) {
    for (int j = 0; j < (int)(W); j++) {
      cin >> G[i][j];
      if (G[i][j] == '.') p0 = pair<int, int>(i, j);
    }
  }
  pair<int, int> p1 = p0;
  int tmp = bfs(p0, p1);
  cout << bfs(p1, p0) << endl;
}
