#include <bits/stdc++.h>
using namespace std;
struct cww {
  cww() {
    ios::sync_with_stdio(false);
    cin.tie(0);
  }
} star;
const long long INF = numeric_limits<long long>::max();
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
int h, w;
string s[20];
int get_res(int i, int j) {
  vector<vector<int> > dist(h, vector<int>(w, -1));
  dist[i][j] = 0;
  queue<pair<int, int> > que;
  que.push(make_pair(i, j));
  int res = 0;
  while (!que.empty()) {
    pair<int, int> current_pos = que.front();
    int x = current_pos.first;
    int y = current_pos.second;
    que.pop();
    for (long long d = long long(0); d < long long(4); ++d) {
      int next_x = x + dx[d];
      int next_y = y + dy[d];
      if (next_x < 0 || next_x >= h || next_y < 0 || next_y >= w) continue;
      if (s[next_x][next_y] == '#') continue;
      if (dist[next_x][next_y] == -1) {
        que.push(make_pair(next_x, next_y));
        dist[next_x][next_y] = dist[x][y] + 1;
        res = max(res, dist[next_x][next_y]);
      }
    }
  }
  return res;
}
int main() {
  cin >> h >> w;
  for (long long i = long long(0); i < long long(h); ++i) cin >> s[i];
  int ans = 0;
  for (long long i = long long(0); i < long long(h); ++i)
    for (long long j = long long(0); j < long long(w); ++j) {
      int res = get_res(i, j);
      ans = max(ans, res);
    }
  cout << ans << endl;
}
