#include <bits/stdc++.h>
using namespace std;
int h, w;
vector<string> maze;
int dh[4] = {-1, 1, 0, 0};
int dw[4] = {0, 0, 1, -1};
int count(pair<int, int> start) {
  queue<pair<int, pair<int, int>>> q;
  int ret = 0;
  q.push(make_pair(0, start));
  vector<vector<int>> cur_maze(h, vector<int>(w, -1));
  while (!q.empty()) {
    auto front = q.front();
    q.pop();
    int cost = front.first;
    pair<int, int> cur = front.second;
    if (cur_maze[cur.first][cur.second] < 0 ||
        cur_maze[cur.first][cur.second] > cost) {
      ret = max(ret, cost);
      cur_maze[cur.first][cur.second] = cost;
    }
    for (int i = 0; i < 4; i++) {
      int nh = cur.first + dh[i];
      int nw = cur.second + dw[i];
      if (nh >= 0 && nh < h && nw >= 0 && nw < w && maze[nh][nw] == '.' &&
          cur_maze[nh][nw] < 0) {
        q.push(make_pair(cost + 1, make_pair(nh, nw)));
      }
    }
  }
  return ret;
}
int main() {
  cin >> h >> w;
  maze.resize(h);
  for (int i = 0; i < h; i++) {
    cin >> maze[i];
  }
  int ans = 0;
  for (int i = 0; i < h; i++) {
    for (int k = 0; k < w; k++) {
      if (maze[i][k] != '.') {
        continue;
      }
      pair<int, int> start = make_pair(i, k);
      ans = max(ans, count(start));
    }
  }
  cout << ans << endl;
  return 0;
}
