#include <bits/stdc++.h>
using namespace std;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  long long H, W;
  cin >> H >> W;
  vector<vector<int>> map(H, vector<int>(W));
  string s;
  for (int i = 0; i < H; i++) {
    cin >> s;
    for (int j = 0; j < W; j++) {
      if (s[j] == '#') {
        map[i][j] = 1;
      }
    }
  }
  deque<pair<long long, long long>> q;
  deque<long long> move_num;
  long long tmp_l = 0;
  vector<vector<int>> map_flag(H, vector<int>(W));
  long long ans = 1;
  long long h, w;
  pair<long long, long long> tmp_q;
  long long max_l = 0;
  long long move[2] = {-1, 1};
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      if (map[i][j] == 1) {
        continue;
      }
      map_flag = map;
      tmp_l = 0;
      q.push_back(pair<long long, long long>(i, j));
      move_num.push_back(tmp_l);
      while (!q.empty()) {
        tmp_q = q.front();
        h = tmp_q.first;
        w = tmp_q.second;
        tmp_l = move_num.front();
        q.pop_front();
        move_num.pop_front();
        ++tmp_l;
        for (long long k : move) {
          if (0 <= h + k && h + k < H) {
            if (map_flag[h + k][w] == 0) {
              map_flag[h + k][w] = 1;
              q.push_back(pair<long long, long long>(h + k, w));
              move_num.push_back(tmp_l);
              max_l = max(max_l, tmp_l);
            }
          }
        }
        for (long long k : move) {
          if (0 <= w + k && w + k < W) {
            if (map_flag[h][w + k] == 0) {
              map_flag[h][w + k] = 1;
              q.push_back(pair<long long, long long>(h, w + k));
              move_num.push_back(tmp_l);
              max_l = max(max_l, tmp_l);
            }
          }
        }
      }
    }
  }
  cout << max_l << "\n";
  return 0;
}
