#include <bits/stdc++.h>
using namespace std;
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;
}
template <typename T>
using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
const long long INF = 1LL << 60;
const long long MOD = 1e9 + 7;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
int calulate_distance(vector<string> field, int H, int W, int sh, int sw,
                      int gh, int gw) {
  queue<pair<int, int>> que;
  vector<vector<int>> dist(30, vector<int>(30));
  for (int i = 0; i < 30; i++) {
    for (int j = 0; j < 30; j++) {
      dist[i][j] = -1;
    }
  }
  pair<int, int> p = make_pair(sh, sw);
  que.push(p);
  dist[sh][sw] = 0;
  int ans = 0;
  while (!que.empty()) {
    pair<int, int> p = que.front();
    que.pop();
    for (int dir = 0; dir < 4; dir++) {
      int nh = p.first + dx[dir];
      int nw = p.second + dy[dir];
      if (nh < 0 || nh >= H || nw < 0 || nw >= W) continue;
      if (field[nh][nw] == '#') continue;
      if (dist[nh][nw] != -1) continue;
      pair<int, int> np = make_pair(nh, nw);
      dist[nh][nw] = dist[p.first][p.second] + 1;
      que.push(np);
      ans = max(ans, dist[nh][nw]);
    }
  }
  return ans;
}
int main() {
  int H, W;
  cin >> H >> W;
  vector<string> field;
  field.resize(H);
  for (int h = 0; h < H; ++h) cin >> field[h];
  int ans = 0;
  for (int sh = 0; sh < H; sh++) {
    for (int sw = 0; sw < W; sw++) {
      for (int gh = 0; gh < H; gh++) {
        for (int gw = 0; gw < W; gw++) {
          ans = max(ans, calulate_distance(field, H, W, sh, sw, gh, gw));
        }
      }
    }
  }
  cout << ans << endl;
}
