#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
const int inf = (int)1e9 + 7;
const long long INF = 1LL << 60;
using ii = pair<int, int>;
using ll = long long;
using vi = vector<int>;
using vd = vector<double>;
using vb = vector<bool>;
using vl = vector<ll>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
using vvb = vector<vector<bool>>;
using vii = vector<pair<int, int>>;
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }
ll LCM(ll a, ll b) { return (a * b) / GCD(a, b); }
int round_int(int a, int b) { return (a + (b - 1)) / b; }
vector<pair<ll, int>> factorize(ll n) {
  vector<pair<ll, int>> res;
  for (ll i = 2; i * i <= n; ++i) {
    if (n % i) continue;
    res.emplace_back(i, 0);
    while (n % i == 0) {
      n /= i;
      res.back().second++;
    }
  }
  if (n != 1) res.emplace_back(n, 1);
  return res;
}
constexpr array<int, 9> dx = {0, 1, 0, -1, -1, 1, 1, -1, 0};
constexpr array<int, 9> dy = {1, 0, -1, 0, 1, 1, -1, -1, 0};
constexpr auto MAX = 100010;
int h, w;
vs table;
int DFS(vs t, ii start) {
  queue<ii> que;
  vvb checked(h, vector<bool>(w));
  vvi depth(h, vector<int>(w));
  que.push(start);
  checked[start.first][start.second] = true;
  while (!que.empty()) {
    ii now = que.front();
    que.pop();
    for (int k = 0; k < 4; k++) {
      int y = now.first + dy[k];
      int x = now.second + dx[k];
      if (0 <= x && x < w && 0 <= y && y < h && checked[y][x] == false &&
          t[y][x] == '.') {
        checked[y][x] = true;
        que.push({y, x});
        depth[y][x] = depth[now.first][now.second] + 1;
      }
    }
  }
  int mx = 0;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      mx = max(mx, depth[i][j]);
    }
  }
  return mx;
}
int main() {
  cin >> h >> w;
  table.resize(h);
  for (int i = 0; i < h; i++) {
    cin >> table[i];
  }
  int ans = 0;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      ans = max(ans, DFS(table, {i, j}));
    }
  }
  cout << ans << endl;
}
