#define _USE_MATH_DEFINES

#include <iostream>
#include <cstdio>
#include <string>
#include <cstdlib>
#include <set>
#include <utility>
#include <vector>
#include <list>
#include <algorithm>
#include <regex>
#include <cmath>
#include <map>
#include <iterator>
#include <climits>
#include <numeric>
#include <bitset>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <queue>
#include <deque>
#include <stack>
#include <array>
#include <valarray>
#include <complex>
#include <random>
#include <functional>
#include <cassert>
#include <chrono>
#include <memory>

using namespace std;

#define int long long
//region TEMPLATE
#define double long double
typedef long long ll;
typedef unsigned long long ull;

template<typename T>
void __read(T &a) { cin >> a; }

template<typename T, typename ... Args>
void __read(T &a, Args &... args) {
    cin >> a;
    __read(args...);
}

#define make(t, ...) t __VA_ARGS__; __read(__VA_ARGS__)
#define makev(a, n) VI a(n); FOR(n) cin >> a[i];
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define FORIT(p) for(auto it = p.begin(); it != p.end(); it++)
#define FOR(b) for(signed i = 0; i <(b); i++)
#define FORE(i, l, r) for(int i = (l); i < (r); i++)
#define NFOR(i, n) for(int i = (((int) n)-1); i >= 0; i--)
typedef vector<int> VI;
typedef vector<vector<int>> VVI;
typedef pair<int, int> PII;
typedef pair<pair<int, int>, int> PPII;
constexpr ll M7 = 1000000007ll;
constexpr ll M9 = 1000000009ll;
constexpr ll MFFT = 998244353ll;
template<class T>
void outv(T &a) { for (auto &x : a) cout << x << ' '; }
static mt19937 rnd(static_cast<unsigned>(chrono::steady_clock::now().time_since_epoch().count())); // NOLINT(cert-err58-cpp)
template<class T>
static auto __super_speed__ = (ios_base::sync_with_stdio(0), cin.tie(
        0)); // NOLINT(cert-err58-cpp,cppcoreguidelines-interfaces-global-init)
//endregion


int32_t main() {
    make(int, n, m);
    vector<string> a(n);
    for(int i = 0; i < n; ++i){
        cin >> a[i];
    }
    int ans = 0;
    for(int x1 = 0; x1 < n; ++x1){
        for(int y1 = 0; y1 < m; ++y1){
            if (a[x1][y1] == '#'){
                continue;
            }
            for(int x2 = 0; x2 < n; ++x2){
                for(int y2 = 0; y2 < m; ++y2){
                    queue<PII> q;
                    q.emplace(x1, y1);
                    VVI dist(n, VI(m, M7));
                    dist[x1][y1] = 0;
                    while(!q.empty()){
                        int x = q.front().first;
                        int y = q.front().second;
                        q.pop();
                        if (x > 0 && dist[x - 1][y] == M7 && a[x - 1][y] != '#'){
                            dist[x - 1][y] = dist[x][y] + 1;
                            q.emplace(x - 1, y);
                        }
                        if (x + 1 < n && dist[x + 1][y] == M7 && a[x + 1][y] != '#'){
                            dist[x + 1][y] = dist[x][y] + 1;
                            q.emplace(x + 1, y);
                        }
                        if (y > 0 && dist[x][y - 1] == M7 && a[x][y - 1] != '#'){
                            dist[x][y - 1] = dist[x][y] + 1;
                            q.emplace(x, y - 1);
                        }
                        if (y + 1 < m && dist[x][y + 1] == M7 && a[x][y + 1] != '#'){
                            dist[x][y + 1] = dist[x][y] + 1;
                            q.emplace(x, y + 1);
                        }
                    }
                    if (dist[x2][y2] != M7){
                        ans = max(ans, dist[x2][y2]);
                    }
                }
            }
        }
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 256