#include <bits/stdc++.h>
using namespace std;
int H, W;
const int INF = 1e9 + 1;
int ht[4] = {0, 1, 0, -1};
int wt[4] = {1, 0, -1, 0};
int bfs(vector<string> s, pair<int, int> start, pair<int, int> goal) {
  int cost[H][W];
  for (int hi = 0; hi < H; ++hi)
    for (int wi = 0; wi < W; ++wi) cost[hi][wi] = INF;
  cost[start.first][start.second] = 0;
  queue<pair<int, int>> q;
  q.push(start);
  while (!q.empty()) {
    pair<int, int> now = q.front();
    q.pop();
    if (now.first == goal.first && now.second == goal.second) continue;
    for (int i = 0; i < 4; ++i) {
      int nh = now.first + ht[i];
      int nw = now.second + wt[i];
      if (!(0 <= nh && nh <= H)) continue;
      if (!(0 <= nw && nw <= W)) continue;
      if (s[nh][nw] == '#') continue;
      if (cost[nh][nw] > cost[now.first][now.second] + 1) {
        cost[nh][nw] = cost[now.first][now.second] + 1;
        q.push(make_pair(nh, nw));
      }
    }
  }
  return cost[goal.first][goal.second];
}
int solve(vector<string> s) {
  int cost = 0;
  for (int hi = 0; hi < H; ++hi) {
    for (int wi = 0; wi < W; ++wi) {
      if (s[hi][wi] == '#') continue;
      for (int hj = 0; hj < H; ++hj) {
        for (int wj = 0; wj < W; wj++) {
          if (s[hj][wj] == '#') continue;
          if (hi == hj && wi == wj) continue;
          pair<int, int> start = make_pair(hi, wi);
          pair<int, int> goal = make_pair(hj, wj);
          cost = max(cost, bfs(s, start, goal));
        }
      }
    }
  }
  return cost;
}
int main() {
  cin >> H >> W;
  vector<string> s(H, "");
  for (int hi = 0; hi < H; ++hi) {
    cin >> s[hi];
  }
  cout << solve(s) << endl;
  return 0;
}
