#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vb = vector<bool>;
using Graph = vector<vi>;
using P = pair<int, int>;
const int MOD = (int)1e9 + 7;
const int INF = (int)1e9;
const ll LINF = (ll)1e18;
const double pi = acos(-1);
template <class t, class u>
inline bool chmax(t& a, u b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class t, class u>
inline bool chmin(t& a, u b) {
  if (b < a) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
istream& operator>>(istream& is, vector<T>& a) {
  for (int i = 0; i < (int)(a.size()); ++i) is >> a[i];
  return is;
}
template <class T>
ostream& operator<<(ostream& os, vector<T>& a) {
  for (int i = 0; i < (int)(a.size()); ++i) os << a[i] << " ";
  return os;
}
template <class T, class U>
istream& operator>>(istream& is, pair<T, U>& p) {
  is >> p.first >> p.second;
  return is;
}
template <class T, class U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}
template <class T, class U>
ostream& operator<<(ostream& os, const map<T, U>& mp) {
  for (auto& t : mp) os << t.first << " " << t.second << "\n";
  return os;
}
const int dx[4] = {0, -1, 0, 1};
const int dy[4] = {-1, 0, 1, 0};
int bfs(const vector<string>& s, int st_x, int st_y) {
  int ret = 0;
  int h = s.size();
  int w = s[0].size();
  queue<pair<int, int>> q;
  q.push({st_x, st_y});
  vector<vi> seen(h, vi(w, -1));
  seen[st_x][st_y] = 0;
  while (q.size()) {
    int x = q.front().first;
    int y = q.front().second;
    q.pop();
    if (ret < seen[x][y]) {
      ret = seen[x][y];
    }
    for (int i = 0; i < (int)(4); ++i) {
      int nx = x + dx[i];
      int ny = y + dy[i];
      if (nx < 0 || nx >= h || ny < 0 || ny >= w || seen[nx][ny] != -1 ||
          s[nx][ny] == '#')
        continue;
      seen[nx][ny] = seen[x][y] + 1;
      q.push({nx, ny});
    }
  }
  return ret;
}
int main() {
  int h, w;
  cin >> h >> w;
  vector<string> s(h);
  for (int i = 0; i < (int)(h); ++i) cin >> s[i];
  int ans = 0;
  for (int i = 0; i < (int)(h); ++i) {
    for (int j = 0; j < (int)(w); ++j) {
      if (s[i][j] == '#') continue;
      chmax(ans, bfs(s, i, j));
    }
  }
  cout << ans << endl;
}
