#include<stdio.h>
#include <vector>
#include <list>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <queue>
 
using namespace std;
 
//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
 
//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}
 
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
 
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
 
//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
 
//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
 
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
 
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

//pair sort
bool compare_by_b(pair<LL, LL> a, pair<LL, LL> b) {
    if(a.second != b.second){
        return a.second < b.second;
    }else{
        return a.first < b.first;
    }
}

int d[21][21];
char map[21][21];
int H,W;
const int INF = 10e5;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1}; 
typedef pair<int, int> P;
bool bfs(int sy, int sx, int gy, int gx){
    FOR(i,1, H+1){
        FOR(j,1, W+1){
            d[i][j] = INF;
        }
    }
    d[sy][sx]=0;
    queue<P> que;
    que.push(P(sy, sx));
    while(que.size()){
        P p = que.front();que.pop();
        if(p.first==gy && p.second==gx){return true;}
        REP(i, 4){
            P q = P(p.first+dy[i], p.second+dx[i]);
            
            if(map[q.first][q.second]=='.'&&d[q.first][q.second]==INF && 0<q.first && q.first<=H && 0<q.second && q.second<=W){
                que.push(q);
                d[q.first][q.second]=d[p.first][p.second]+1;
            }
        }
    }
    return false;
}

int main(){
    // Failed to predict input format
    cin>>H>>W;
    FOR(i,1,H+1){
        FOR(j,1,W+1){
            cin>>map[i][j];
        }
    }
    int ans=0;
    FOR(i,1, H+1){
        FOR(j,1, W+1){
            FOR(k,1, H+1){
                FOR(l,1, W+1){
                    if(map[i][j]=='.' && map[k][l]=='.'){
                        if(i==k && j==l)continue;
                        else if (bfs(i, j, k, l))
                            ans=max(ans, d[k][l]);
                    }
                }
            }
            
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256