#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rrep(i,n) for(int (i)=((n)-1);(i)>=0;(i)--)
#define itn int
#define all(x) (x).begin(),(x).end()
#define F first
#define S second
const long long INF = 1LL << 60;
const int MOD = 1000000007;
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; }
//https://www.creativ.xyz/dump-cpp-652/
#define repi(itr, ds) for (auto itr = ds.begin(); itr != ds.end(); itr++)
 
// vector
template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
    for (T &x : vec) is >> x;
    return is;
}
// pair
template <typename T, typename U>
ostream &operator<<(ostream &os, pair<T, U> &pair_var) {
    os << "(" << pair_var.first << ", " << pair_var.second << ")";
    return os;
}
// vector
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
    os << "{";
    for (int i = 0; i < vec.size(); i++) {
        os << vec[i] << (i + 1 == vec.size() ? "" : ", ");
    }
    os << "}";
    return os;
}
// map
template <typename T, typename U>
ostream &operator<<(ostream &os, map<T, U> &map_var) {
    os << "{";
    repi(itr, map_var) {
        os << *itr;
        itr++;
        if (itr != map_var.end()) os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
// set
template <typename T>
ostream &operator<<(ostream &os, set<T> &set_var) {
    os << "{";
    repi(itr, set_var) {
        os << *itr;
        itr++;
        if (itr != set_var.end()) os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
 
#define DUMPOUT cerr
 
void dump_func() {
    DUMPOUT << endl;
}
template <class Head, class... Tail>
void dump_func(Head &&head, Tail &&... tail) {
    DUMPOUT << head;
    if (sizeof...(Tail) > 0) {
        DUMPOUT << ", ";
    }
    dump_func(std::move(tail)...);
}

#ifdef DEBUG_
#define DEB
#define dump(...)                                                              \
    DUMPOUT << "  " << string(#__VA_ARGS__) << ": "                            \
            << "[" << to_string(__LINE__) << ":" << __FUNCTION__ << "]"        \
            << endl                                                            \
            << "    ",                                                         \
        dump_func(__VA_ARGS__)
#else
#define DEB if (false)
#define dump(...)
#endif

signed main(void) { cin.tie(0); ios::sync_with_stdio(false);
    int h,w; cin>>h>>w;
    vector <vector<char>> grid(h,vector <char>(w));
    rep(i,h){
        rep(j,w) cin>>grid[i][j];
    }
    vector <vector<int>> d(500,vector <int>(500, INF));
    rep(i,h){
        rep(j,w){
            if(grid[i][j] == '#') continue;
            
            if(i-1 >= 0){
                if(grid[i-1][j] == '.'){
                d[j + (i*w)][j + ((i-1)*w)] = 1;
                d[j + ((i-1)*w)][j + (i*w)] = 1;
                }
            }
            if(i + 1 < h){
                if(grid[i+1][j] == '.'){
                d[j + (i*w)][j + ((i+1)*w)] = 1;
                d[j + ((i+1)*w)][j + (i*w)] = 1;
                }
            }
            if(j -1 >= 0){
                if(grid[i][j-1] == '.'){
                d[j + (i*w)][j-1 + i*w] = 1;
                d[j -1 + (i*w)][j + (i*w)] = 1;
                }
            }
            if(j + 1 < w){
                if(grid[i][j+1] == '.'){
                d[j + (i*w)][j+1 + i*w] = 1;
                d[j + 1 + (i*w)][j + (i*w)] = 1;
                }
            }
        }
    }
    for(int k=0;k<500;k++){
        for(int i=0;i<500;i++){
            for(int j=0;j<500;j++){
                chmin(d[i][j],d[i][k]+d[k][j]);
            }
        }
    }
    int ans = 1;
    rep(i, 500){
        rep(j,500){
            if(d[i][j] < h*w){
                chmax(ans, d[i][j]);
            }
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 2304