#include <bits/stdc++.h>
using namespace std;
int H, W;
vector<vector<char>> S(50, vector<char>(50));
const pair<int, int> points[4] = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}};
int compute_dist(pair<int, int> s) {
  vector<vector<int>> dist(H, vector<int>(W, 0));
  int dmax = 0;
  queue<pair<int, int>> q;
  q.push(s);
  while (!q.empty()) {
    pair<int, int> cur = q.front();
    q.pop();
    for (int i = 0; i < 4; ++i) {
      pair<int, int> next =
          make_pair(cur.first + points[i].first, cur.second + points[i].second);
      if (next.first >= 0 && next.first < W && next.second >= 0 &&
          next.second < H && S[next.second][next.first] == '.') {
        if (dist[next.second][next.first] == 0 &&
            !(next.first == s.first && next.second == s.second)) {
          q.push(next);
          dmax = dist[next.second][next.first] =
              dist[cur.second][cur.first] + 1;
        }
      }
    }
  }
  return dmax;
}
int main() {
  cin >> H >> W;
  for (int i = 0; i < H; ++i) {
    for (int j = 0; j < W; ++j) cin >> S[i][j];
  }
  int dmax = 0;
  for (int i = 0; i < H; ++i) {
    for (int j = 0; j < W; ++j) {
      if (S[j][i] == '.') {
        int d = compute_dist(make_pair(j, i));
        dmax = max(d, dmax);
      }
    }
  }
  cout << dmax << endl;
}
