#include <bits/stdc++.h>
using namespace std;
using ll = long long;
bool can_move_right(vector<char> &s, ll i, ll h, ll w) {
  if ((i + 1) % w == 0) return false;
  if (s[i + 1] == '#') return false;
  if (s[i + 1] == '.') return true;
}
bool can_move_left(vector<char> &s, ll i, ll h, ll w) {
  if (i % w == 0) return false;
  if (s[i - 1] == '#') return false;
  if (s[i - 1] == '.') return true;
}
bool can_move_bottom(vector<char> &s, ll i, ll h, ll w) {
  if (i >= (h - 1) * w) return false;
  if (s[i + w] == '#') return false;
  if (s[i + w] == '.') return true;
}
bool can_move_upper(vector<char> &s, ll i, ll h, ll w) {
  if (i < w) return false;
  if (s[i - w] == '#') return false;
  if (s[i - w] == '.') return true;
}
ll eval(vector<char> &s, ll i, ll h, ll w, ll end) {
  if (i == end) return 1;
  ll cost_right = 1;
  ll cost_left = 1;
  ll cost_bottom = 1;
  ll cost_upper = 1;
  bool flag = false;
  char s_tmp = s[i];
  s[i] = '#';
  if (can_move_right(s, i, h, w)) {
    cost_right += eval(s, i + 1, h, w, end);
    flag = true;
  } else {
    cost_right = INT_MAX;
  }
  if (can_move_left(s, i, h, w)) {
    cost_left += eval(s, i - 1, h, w, end);
    flag = true;
  } else {
    cost_left = INT_MAX;
  }
  if (can_move_bottom(s, i, h, w)) {
    cost_bottom += eval(s, i + w, h, w, end);
    flag = true;
  } else {
    cost_bottom = INT_MAX;
  }
  if (can_move_upper(s, i, h, w)) {
    cost_upper += eval(s, i - w, h, w, end);
    flag = true;
  } else {
    cost_upper = INT_MAX;
  }
  s[i] = s_tmp;
  if (!flag) return INT_MAX;
  ll min1 = min(cost_right, cost_left);
  ll min2 = min(cost_bottom, cost_upper);
  return min(min1, min2);
}
int main(void) {
  ll h, w;
  cin >> h >> w;
  vector<char> s(h * w), s_tmp(h * w);
  for (ll(i) = (0); (i) < (h * w); ++(i)) cin >> s[i];
  ll ans = 0;
  for (ll(i) = (0); (i) < (h * w); ++(i)) {
    if (s[i] != '#') {
      s_tmp = s;
      for (ll(j) = (0); (j) < (h * w); ++(j)) {
        if (s[j] != '#' && j != i) {
          ans = max(ans, eval(s_tmp, i, h, w, j));
        }
      }
    }
  }
  cout << ans - 1 << endl;
}
