#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
void Main() {
  int H, W;
  cin >> H >> W;
  int board[H][W];
  for (ll i = 0; i < (ll)(H); i++) {
    for (ll j = 0; j < (ll)(W); j++) {
      char x;
      cin >> x;
      if (x == '.') {
        board[i][j] = 1;
      } else {
        board[i][j] = 0;
      }
    }
  }
  ll total_ans = 0;
  for (ll i = 0; i < (ll)(H); i++) {
    for (ll j = 0; j < (ll)(W); j++) {
      ll dist[H][W];
      for (ll k = 0; k < (ll)(H); k++) {
        for (ll l = 0; l < (ll)(W); l++) {
          dist[k][l] = INF;
        }
      }
      queue<tuple<int, int, int>> fifo;
      fifo.push(make_tuple(i, j, 0));
      while (fifo.size() > 0) {
        tuple<int, int, int> tmp = fifo.front();
        int& cur_y = get<0>(tmp);
        int& cur_x = get<1>(tmp);
        int& cur_cost = get<2>(tmp);
        dist[cur_y][cur_x] = cur_cost;
        fifo.pop();
        if (dist[cur_y][cur_x] == INF) {
          continue;
        } else {
          for (ll k = 0; k < (ll)(4); k++) {
            int next_y = cur_y + dy[k];
            int next_x = cur_x + dx[k];
            if (0 <= next_y && next_y < H && 0 <= next_x && next_x < W &&
                dist[next_y][next_x] == INF && board[next_y][next_x]) {
              fifo.push(make_tuple(next_y, next_x, cur_cost + 1));
            }
          }
        }
      }
      ll ans = 0;
      for (ll k = 0; k < (ll)(H); k++) {
        for (ll l = 0; l < (ll)(W); l++) {
          if (dist[k][l] != INF and dist[k][l] > ans) {
            ans = dist[k][l];
          }
        }
      }
      if (ans != INF and ans > total_ans) {
        total_ans = ans;
      }
    }
  }
  cout << total_ans << endl;
}
int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  Main();
  return 0;
}
