#include <bits/stdc++.h>	
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define ld long double
#define pii pair <int, int>
#define sz(a) (int)(a.size()) 
#define resize(v) v.resize(unique(all(v)) - v.begin()); 
#define all(a) a.begin(), a.end()
#define forit(it, s) for(__typeof(s.begin()) it = s.begin(); it != s.end(); it ++)

// random_device rd; mt19937 g(rd());    
                                        	
using namespace std;
using namespace __gnu_pbds;
 
void Fast_Read_Out()
{
    ios_base::sync_with_stdio(0);
    cin.tie(), cout.tie();
}
 
void Random()
{
    unsigned int seed;                                                                        
    asm("rdtsc" : "=A" (seed));
    srand(seed);        
}
 
unsigned int Time()
{
     unsigned int time = clock() / 1000.00;                           
     return time;
}

template <typename T> using ordered_set = tree <T, null_type, less <T>, rb_tree_tag, tree_order_statistics_node_update>; 
 
const int mod = (int)1e9 + 7;
const int dx[] = {0, -1, 0, 1};
const int dy[] = {1, 0, -1, 0};
 
int n, m;
char a[22][22];
int d[22][22];
int ans;
queue <pair <int, int> > q;

int main ()
{
	#ifdef JUDGE
		freopen("input.txt", "r", stdin);
	#endif		
	Fast_Read_Out();
	Random();   
	cin >> n >> m;
	for(int i = 1; i <= n; i++)
		for(int j = 1; j <= m; j++)
			cin >> a[i][j];
	for(int i1 = 1; i1 <= n; i1++)
		for(int j1 = 1; j1 <= m; j1++)
			for(int i2 = 1; i2 <= n; i2++)
				for(int j2 = 1; j2 <= m; j2++)
				{
					for(int i = 1; i <= n; i++)
						for(int j = 1; j <= m; j++)	
							d[i][j] = 0;
					q.push(mp(i1, j1));
					d[i1][j1] = 1;
					while(!q.empty())
					{
						pair <int, int> v = q.front();
						q.pop();
						for(int i = 0; i < 4; i++)
						{
							int nx = dx[i] + v.F;
							int ny = dy[i] + v.S;
							if(!d[nx][ny] && a[nx][ny] == '.')
							{
								q.push(mp(nx, ny));
								d[nx][ny] = d[v.F][v.S] + 1;
							}
						}
					}
					ans = max(ans, d[i2][j2] - 1);
				}
	cout << ans;
}                                