#include <bits/stdc++.h>
using namespace std;
using P = pair<long long, long long>;
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
long long dx[4] = {0, 1, 0, -1};
long long dy[4] = {1, 0, -1, 0};
long long dfs(vector<string>& field, vector<vector<bool>>& seen, long long x,
              long long y, long long gx, long long gy, long long kai,
              long long h, long long w) {
  seen[x][y] = true;
  cout << x << " " << y;
  cout << " " << kai << endl;
  long long res = (1LL << 60);
  if (x == gx && y == gy) return kai;
  for (long long(dd) = (0); (dd) < (4); (dd)++) {
    long long next_x = x + dx[dd], next_y = y + dy[dd];
    cout << " " << next_x << " " << next_y << endl;
    if (next_x < 0 || next_x >= h) continue;
    if (next_y < 0 || next_y >= w) continue;
    if (seen[x + dx[dd]][y + dy[dd]] == true) continue;
    if (field[next_x][next_y] == '#') continue;
    cout << " "
         << "yap" << endl;
    long long hoge = dfs(field, seen, next_x, next_y, gx, gy, kai + 1, h, w);
    chmin(res, hoge);
  }
  return res;
}
int main() {
  long long h, w;
  cin >> h >> w;
  vector<string> field(h);
  for (long long(i) = (0); (i) < (h); (i)++) {
    cin >> field[i];
  }
  long long ans = 0;
  for (long long(sx) = (0); (sx) < (h); (sx)++) {
    for (long long(sy) = (0); (sy) < (w); (sy)++) {
      if (field[sx][sy] == '#') continue;
      vector<vector<long long>> seen(h, vector<long long>(w, -1));
      long long this_ans = 0;
      queue<pair<pair<long long, long long>, long long>> que;
      que.push(make_pair(make_pair(sx, sy), 0));
      while (!que.empty()) {
        long long x = que.front().first.first;
        long long y = que.front().first.second;
        long long kai = que.front().second;
        que.pop();
        seen[x][y] = kai;
        chmax(ans, kai);
        if (seen[y][x] != -1) continue;
        seen[y][x] = 1;
        for (long long(d) = (0); (d) < (4); (d)++) {
          long long next_x = x + dx[d], next_y = y + dy[d];
          if (next_x < 0 || next_x >= h) continue;
          if (next_y < 0 || next_y >= w) continue;
          if (seen[next_x][next_y] != -1) continue;
          if (field[next_x][next_y] == '#') continue;
          que.push(make_pair(make_pair(next_x, next_y), kai + 1));
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}
