#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = (int)(a); i <= (int)(n); ++i)
#define rrep(i, a, n) for (int i = (int)(a); i >= (int)(n); --i)
#define debug(x) cerr << #x << " = " << x << "\n"
#define debugv(x) \
  rep(f, 0, (x.size() - 1)) cerr << x[f] << (f == (x.size() - 1) ? "\n" : " ")
#define debug2(x, y)                       \
  cerr << "(" << #x << "," << #y << ") = " \
       << "(" << x << "," << y << ")\n"
#define all(x) x.begin(), x.end()
#define each(a, x) for (auto& a : (x))
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define int long long
using namespace std;
using pii = pair<int, int>;
using vi = vector<int>;
const int MX = 1e5 + 5, INF = 5LL << 57, MOD = 1e9 + 7;

int H, W;
string S;
vi va, vb;
int field[30][30];

void input() {
  cin >> H >> W;
  rep(i, 1, H) {
    ;
    ;
    rep(j, 1, W) {
      char c;
      cin >> c;
      field[i][j] = (c == '#' ? 0 : 1);
      ;
    }
  };
  ;
}
int dh[4] = {-1, 0, 0, 1};
int dw[4] = {0, -1, 1, 0};
void solve() {
  // rep(i, 1, H) {
  //   rep(j, 1, W) { cout << field[i][j] << " "; }
  //   cout << endl;
  // };
  // 400 とおり？

  // wfs?
  int ans = -1;
  rep(sth, 1, H) {
    ;
    rep(stw, 1, W) {  // wfs
      // set<pii> st;
      if (!field[sth][stw]) continue;
      int table[23][23];
      rep(i, 0, 22) { rep(j, 0, 22) table[i][j] = -1; }
      queue<pii> q;
      q.push(pii(sth, stw));
      table[sth][stw] = 0;
      while (q.size()) {
        // debug(q.size());
        pii qq = q.front();
        q.pop();
        // pii qq = q1.first;
        // st.insert(qq);

        int nowh = qq.first, noww = qq.second;
        // int cnt = q1.second;
        // ans = max(ans, cnt);
        chmax(ans, table[i][j]);
        rep(i, 0, 3) {
          int nexth = nowh + dh[i];
          int nextw = noww + dw[i];
          if (table[nexth][nextw] != -1) {
            continue;
          }
          if ((nexth < 1) || (nextw < 1) || (nexth > H) || (nextw > W)) {
            continue;
          } else {
            if (field[nexth][nextw] && (table[nexth][nextw] == -1)) {
              table[nexth][nextw] = table[nowh][noww] + 1;
              q.push(pii(nexth, nextw));

            } else {
              continue;
            }
          }
        }
      }
      // rep(i, 1, H) {
      //   rep(j, 1, W) {
      //     // debug(table[i][j]);
      //   }
      // }
      // debug2(sth, stw);
      // debug(ans);
    }
  }
  cout << ans << endl;

  ;
}
signed main() {
  input();
  solve();
  return 0;
}
