#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;
}
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
const int INF = 1e9;
const long long LLINF = 1e16;
long long modinv(long long a, long long m) {
  long long b = m, u = 1, v = 0;
  while (b) {
    long long t = a / b;
    a -= t * b;
    swap(a, b);
    u -= t * v;
    swap(u, v);
  }
  u %= m;
  if (u < 0) u += m;
  return u;
}
vector<pair<int, int>> kinbo4(int ch, int cw) {
  vector<pair<int, int>> list(4);
  list[0] = pair<int, int>(ch, cw + 1);
  list[1] = pair<int, int>(ch, cw - 1);
  list[2] = pair<int, int>(ch + 1, cw);
  list[3] = pair<int, int>(ch - 1, cw);
  return list;
}
int main(void) {
  int h, w;
  cin >> h >> w;
  vector<vector<char>> s(h + 2, vector<char>(w + 2, '#'));
  for (long long i = 1, i_len = (h + 1); i < i_len; ++i) {
    for (long long j = 1, j_len = (w + 1); j < j_len; ++j) {
      cin >> s[i][j];
    }
  }
  int amax = 0;
  for (long long i = 1, i_len = (h + 1); i < i_len; ++i) {
    for (long long j = 1, j_len = (w + 1); j < j_len; ++j) {
      queue<pair<int, int>> ta;
      ta.push(pair<int, int>(i, j));
      vector<vector<int>> dis(h + 2, vector<int>(w + 2, 0));
      vector<vector<int>> color(h + 2, vector<int>(w + 2, 0));
      color[i][j]++;
      while (!ta.empty()) {
        pair<int, int> v = ta.front();
        int ch = v.first;
        int cw = v.second;
        ta.pop();
        vector<pair<int, int>> kin4 = kinbo4(ch, cw);
        for (long long k = 0, k_len = (kin4.size()); k < k_len; ++k) {
          int nh = kin4[k].first;
          int nw = kin4[k].second;
          if (s[nh][nw] == '.' && color[nh][nw] == 0) {
            color[nh][nw] = 1;
            dis[nh][nw] = dis[ch][cw] + 1;
            ta.push(kin4[k]);
          }
        }
      }
      for (long long k = 1, k_len = (h + 1); k < k_len; ++k) {
        for (long long m = 1, m_len = (w + 1); m < m_len; ++m) {
          if (dis[k][m] > amax) {
            amax = dis[k][m];
          }
        }
      }
    }
  }
  cout << amax << endl;
  return 0;
}
