#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll INF = 1LL << 60;
vector<vector<char>> vec;
vector<pair<int, int>> direct = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};
int H, W;
int bfs(int x, int y) {
  vector<vector<int>> dist(H, vector<int>(W, -1));
  queue<pair<int, int>> que;
  int ans = 0;
  que.push({x, y});
  dist[x][y] = 0;
  while (!que.empty()) {
    int x = que.front().first;
    int y = que.front().second;
    ans = max(ans, dist[x][y]);
    que.pop();
    for (ll i = (0); (i) < (4); i++) {
      int dx = x + direct[i].first;
      int dy = y + direct[i].second;
      if (dx < 0 || dx >= H || dy < 0 || dy >= W) continue;
      if (vec[dx][dy] == '#') continue;
      if (dist[dx][dy] == -1) {
        dist[dx][dy] = ++dist[x][y];
        que.push({dx, dy});
      }
    }
  }
  return ans;
}
int main() {
  cin >> H >> W;
  vec.resize(H);
  for (ll i = (0); (i) < (H); i++) {
    for (ll k = (0); (k) < (W); k++) {
      char c;
      cin >> c;
      vec[i].push_back(c);
    }
  }
  int ans = 0;
  for (ll x = (0); (x) < (H); x++) {
    for (ll y = (0); (y) < (W); y++) {
      if (vec[x][y] == '#') continue;
      ans = max(ans, bfs(x, y));
    }
  }
  cout << ans << endl;
}
