//#pragma GCC optimize("Ofast")
//#pragma GCC optimize ("unroll-loops")
//#pragma GCC target("avx,avx2,fma")
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define mp make_pair
#define ff first
#define ss second
#define setbits(x) __builtin_popcount(x)
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<db, db> pdd;
typedef vector<int> vi;
#define m1 make_pair
#define in insert
#define pb push_back
#define IOS                           \
    std::ios::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);
#define endl "\n"
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

inline ll gcd(ll a, ll b)
{
    if (a == 0)
        return b;
    return gcd(b % a, a);
}
inline ll power(ll a, ll n, ll m)
{
    if (n == 0)
        return 1;
    ll p = power(a, n / 2, m);
    p = (p * p) % m;
    if (n % 2)
        return (p * a) % m;
    else
        return p;
}
const ll MOD = 1000000007;
const int N = int(3e5) + 999;
#define int long long int
vector<string> a;
int n,m;
int dp1[21][21],dp2[21][21];
int dist[4][2] = {{1,0},{-1,0},{0,-1},{0,1}};

bool check(int x,int y){
	if(x>=n or y>=m or x<0 or y<0 )
		return false;
	if(a[x][y]=='#')
		return false;
	if(dp1[x][y]==1)
		return false;
	dp1[x][y]=1;
	return true;
}

bool ch(int x,int y){
	if(x>=n or y>=m or x<0 or y<0 )
		return false;
	if(a[x][y]=='#')
		return false;
	if(dp2[x][y]==1)
		return false;
	dp2[x][y]=1;
	return true;
}

pair<int,int> bfs1(int x,int y){

	pair<pair<int,int>,int> mx = {{x,y},0};
	queue<pair<pair<int,int>,int>> q;
	q.push({{x,y},0});
	dp1[x][y]=1;
	while(!q.empty()){
		auto it = q.front();
		q.pop();
		int nx = it.ff.ff,ny = it.ff.ss,dpar = it.ss;
		for(int p=0;p<4;p++){
			int i = dist[p][0],j=dist[p][1];
			if(check(nx+i,ny+j)){
				dp1[nx+i][ny+j]=1;
				if(mx.ss<dpar+1){
					mx = {{nx+i,ny+j},dpar+1};
				}
				q.push({{nx+i,ny+j},dpar+1});
			}
		}
		
	}

	return mx.ff;
}

int bfs2(int x,int y){

	pair<pair<int,int>,int> mx = {{x,y},0};
	queue<pair<pair<int,int>,int>> q;
	q.push({{x,y},0});
	dp2[x][y]=1;
	while(!q.empty()){
		auto it = q.front();
		q.pop();
		int nx = it.ff.ff,ny = it.ff.ss,dpar = it.ss;
		for(int p=0;p<4;p++){
			int i = dist[p][0],j=dist[p][1];
			if(ch(nx+i,ny+j)){
				dp2[nx+i][ny+j]=1;
				if(mx.ss<dpar+1){
					mx = {{nx+i,ny+j},dpar+1};
				}
				q.push({{nx+i,ny+j},dpar+1});
			}
		}
	}

	return mx.ss;
}

int32_t main(){
    IOS;
    
    cin>>n>>m;
    a.resize(n);
    
    memset(dp1,-1,sizeof dp1);
    memset(dp2,-1,sizeof dp2);

    for(int i=0;i<n;i++)
    	cin>>a[i];
    
    int ans = 0;

    for(int i =0;i<n;i++){
    	for(int j=0;j<m;j++){
    		if(dp1[i][j]==-1 and a[i][j]!='#'){
    			auto node = bfs1(i,j);
    			ans = max(ans,bfs2(node.ff,node.ss));
    			break;
    		}
    	}
    }
    cout<<ans<<endl;

    return 0;
}