#include <bits/stdc++.h>

#define REP(i, n) for (int i = 0; i < n; i++)
#define ALL(obj) obj.begin(), obj.end()

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;
}

const int iINF = 1e9;
const long long llINF = 1e18;
const int MOD = 1e9 + 7;

using namespace std;

template <int MOD>
struct Fp {
    long long val;
    constexpr Fp(long long v = 0) noexcept : val(v % MOD) {
        if (val < 0) val += MOD;
    }
    constexpr int getmod() { return MOD; }
    constexpr Fp operator-() const noexcept { return val ? MOD - val : 0; }
    constexpr Fp operator+(const Fp& r) const noexcept { return Fp(*this) += r; }
    constexpr Fp operator-(const Fp& r) const noexcept { return Fp(*this) -= r; }
    constexpr Fp operator*(const Fp& r) const noexcept { return Fp(*this) *= r; }
    constexpr Fp operator/(const Fp& r) const noexcept { return Fp(*this) /= r; }
    constexpr Fp& operator+=(const Fp& r) noexcept {
        val += r.val;
        if (val >= MOD) val -= MOD;
        return *this;
    }
    constexpr Fp& operator-=(const Fp& r) noexcept {
        val -= r.val;
        if (val < 0) val += MOD;
        return *this;
    }
    constexpr Fp& operator*=(const Fp& r) noexcept {
        val = val * r.val % MOD;
        return *this;
    }
    constexpr Fp& operator/=(const Fp& r) noexcept {
        long long a = r.val, b = MOD, u = 1, v = 0;
        while (b) {
            long long t = a / b;
            a -= t * b;
            swap(a, b);
            u -= t * v;
            swap(u, v);
        }
        val = val * u % MOD;
        if (val < 0) val += MOD;
        return *this;
    }
    constexpr bool operator==(const Fp& r) const noexcept { return this->val == r.val; }
    constexpr bool operator!=(const Fp& r) const noexcept { return this->val != r.val; }
    friend constexpr ostream& operator<<(ostream& os, const Fp<MOD>& x) noexcept { return os << x.val; }

    friend constexpr Fp<MOD> modpow(const Fp<MOD>& a, long long n) noexcept {
        if (n == 0) return 1;
        auto t = modpow(a, n / 2);
        t = t * t;
        if (n & 1) t = t * a;
        return t;
    }
};

using mint = Fp<MOD>;

int H, W;
vector<string> S;
int cost[20][20];

int dx[4] = {0, 0, 1, -1};
int dy[4] = {1, -1, 0, 0};

int bfs(int sx, int sy, int gx, int gy) {
    int res = 0;
    queue<pair<int, int>> q;
    q.push(make_pair(sx, sy));
    cost[sy][sx] = 0;
    while (q.size()) {
        auto n = q.front();
        q.pop();
        REP(i, 4) {
            int nx = n.first + dx[i], ny = n.second + dy[i];
            if (nx < 0 || ny < 0 || nx >= W || ny >= H || S[ny][nx] == '#') continue;
            if (cost[ny][nx] != -1) continue;
            cost[ny][nx] = cost[n.second][n.first] + 1;
            q.push(make_pair(nx, ny));
        }
    }

    if (cost[gy][gx] != -1) {
        return cost[gy][gx];
    } else {
        return 0;
    }
}

int main() {
    cin >> H >> W;
    REP(i, H) {
        string in;
        cin >> in;
        S.push_back(in);
    }

    int ans = 0;
    memset(cost, -1, sizeof(cost));
    REP(i, H) REP(j, W) REP(k, H) REP(l, W) {
        memset(cost, -1, sizeof(cost));
        if (S[i][j] == '#' || S[k][l] == '#') continue;
        if (i == k && j == l) continue;
        chmax(ans, bfs(j, i, l, k));
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256