#include <bits/stdc++.h>
using namespace std;
long long MOD = 1000000000 + 7;
int H, W;
vector<string> v;
int dx[4] = {0, 0, 1, -1};
int dy[4] = {1, -1, 0, 0};
int solve(int x1, int y1) {
  vector<vector<bool>> check(H, vector<bool>(W, false));
  map<pair<int, int>, int> dist;
  pair<int, int> p = make_pair(x1, y1);
  dist[p] = 0;
  queue<pair<int, int>> q;
  q.push(p);
  int ans = 0;
  while (!q.empty()) {
    pair<int, int> now = q.front();
    q.pop();
    int now_x = now.first;
    int now_y = now.second;
    check[now_x][now_y] = true;
    for (int i = 0; i < 4; i++) {
      int next_x = now_x + dx[i];
      int next_y = now_y + dy[i];
      pair<int, int> next = make_pair(next_x, next_y);
      if (check[next_x][next_y]) continue;
      if (next_x >= 0 && next_x < H) {
        if (next_y >= 0 && next_y < W) {
          if (v.at(next_x).at(next_y) == '.') {
            dist[next] = dist[now] + 1;
            ans = max(dist[next], ans);
            q.push(next);
          }
        }
      }
    }
  }
  return ans;
}
int main() {
  cout << setprecision(10);
  cin >> H >> W;
  v.assign(H, "");
  for (int i = 0; i < H; i++) {
    cin >> v.at(i);
  }
  int ans = 0;
  for (int x1 = 0; x1 < H; x1++) {
    for (int y1 = 0; y1 < W; y1++) {
      if (v.at(x1).at(y1) == '#') continue;
      ans = max(ans, solve(x1, y1));
    }
  }
  cout << ans << endl;
}
