#include <bits/stdc++.h>
using namespace std;
int h, w;
vector<string> maze;
int dx[4] = {-1, 1, 0, 0};
int dy[4] = {0, 0, 1, -1};
int count(pair<int, int> start) {
  queue<tuple<int, pair<int, int>>> q;
  int ret = 0;
  q.push(make_tuple(0, start));
  vector<string> cur_maze = maze;
  while (!q.empty()) {
    auto f = q.front();
    q.pop();
    ret = get<0>(f);
    pair<int, int> cur = get<1>(f);
    cur_maze[cur.first][cur.second] = '#';
    for (int i = 0; i < 4; i++) {
      int nh = cur.first + dx[i];
      int nw = cur.second + dy[i];
      if (nh >= 0 && nh < h && nw >= 0 && nw < w && cur_maze[nh][nw] == '.') {
        q.push(make_tuple(ret + 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;
}
