#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define mod 1000000007
#define MAX 1000000000000000
#define all(v) v.begin(),v.end()
#define rep(i,a,b) for(i=(ll)a;i<(ll)b;i++)
#define revrep(i,a,b) for(i=(ll)a;i>=(ll)b;i--)
#define ii pair<ll, pair<ll,ll> >
#define MP make_pair
#define pb push_back
#define f first
#define se second
#define ll long long int
#define vi vector<ll>
ll modexp(ll a,ll b){ ll res = 1; while(b > 0){  if(b & 1) res = (res * a)%mod;  a = (a * a)%mod;  b/=2;  }  return res; }
#define rs resize
typedef tree< ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update > OST;
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <typename Arg1>
    void __f(const char* name, Arg1&& arg1){
        cout << name << " : " << arg1 << endl;
    }
    template <typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
    }
#else
#define trace(...)
#endif

const ll N = 20 + 5;
ll i,j,a,b,n,m,k,ans,st = 1, dx[] = {-1, 0, 1, 0}, dy[] = {0, 1, 0, -1};
char c[N][N];
queue<ii> q;
ll visit[N][N];
int main()
{
    std::ios_base::sync_with_stdio(false); cin.tie(NULL);
    cin>>n>>m;
    rep(i,1,n + 1) rep(j,1,m + 1) cin>>c[i][j];
    rep(i,1,n + 1) rep(j,1,m + 1) if(c[i][j] == '.'){
        q.push({0, {i, j}});
        while(!q.empty()){
            ii p = q.front();
            q.pop();
            ans = max(ans, p.f);
            for(k = 0;k < 4;k += 1){
                a = p.se.f + dx[k];
                b = p.se.se + dy[k];
                if(a >= 1 && b >= 1 && a <= n && b <= m && c[a][b] == '.' && visit[a][b] != st){
                    q.push({p.f + 1, {a, b}});
                    visit[a][b] = st;
                }
            }
        }
        st += 1;
    }
    cout<<ans;
    return 0;
}