#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 int                 long long int
#define ull                 unsigned int
#define ld                  long double
#define pb                  push_back
#define ff                  first
#define ss                  second
#define S(arr)              sort(arr.begin(),arr.end());
#define RS(arr)              sort(arr.rbegin(),arr.rend());
#define R(arr)              reverse(arr.begin(),arr.end());
#define si                  set <int>
#define vi                  vector <int>
#define vvi                 vector <vector <int>>
#define vs                  vector <string>
#define mp                  make_pair
#define pii                 pair <int, int>
#define vpi                 vector <pii>
#define vpp                 vector <pair<int, pii>>
#define mii                 map <int, int>
#define mci                 map<char, int>
#define mpi                 map <pii, int>
#define spi                 set <pii>
#define speed               ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl                "\n"
#define all(p)              p.begin(), p.end()
#define T                   int tcf;cin>>tcf;while(tcf--)
#define que_max(t)             priority_queue <t>
#define que_min(t)             priority_queue <t, vector<t>, greater<t>>
#define debuga(a, l, r)     for(auto x:a)cout<<x<<" ";cout<<endl;
#define debug1(x)           cout << #x " = " << x << endl;
#define debug2(x,y)         cout << #x " = " << x << " " << #y " = " << y << endl;
#define debug3(x,y,z)       cout << #x " = " << x << " " << #y " = " << y << " " << #z " = " << z << endl;
#define debug4(x,y,z,w)     cout << #x " = " << x << " " << #y " = " << y << " " << #z " = " << z << " " << #w " = " << w << endl;
#define debug5(x,y,z,w,v)   cout << #x " = " << x << " " << #y " = " << y << " " << #z " = " << z << " " << #w " = " << w << " " << #v " = " << v << endl;
#define debug6(x,y,z,w,v,a) debug3(a, y, x)debug3(w, v, a)
#define p2d(v)          for(auto a:v){for(auto b:a)cout<<b<<" ";cout<<endl;}
#define p1d(v)              for(auto a:v)cout<<a<<" ";cout<<endl;
#define ppi(v)  for(auto a:v)cout<<a.ff<<" "<<a.ss<<endl;
 
 
void read(int n=10){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cout<<setprecision(n)<<fixed;
    // #ifndef ONLINE_JUDGE
    //      freopen("input.txt",  "r",  stdin);
    //      freopen("output.txt", "w", stdout);
    // #endif
}
 
int M = 1e9 + 7;
int M1 = 998244353;
#define qqq 4000005
 
vs graph;
 
int32_t main(){
    read();
    int n,m;
    cin>>n>>m;
    graph.resize(n);
    for(int i=0;i<n;i++){
        cin>>graph[i];
    }
    int ans = 0;
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            if(graph[i][j] == '.'){
                vvi visited(n,vi(m));
                queue<pii>pn;
                int curr = 0;
                pn.push({i,j});
                pii tem = mp(-1,-1);
                visited[i][j] = 1;
                pn.push({-1,-1});
                while(pn.size()>1){
                    pii front = pn.front();
                    pn.pop();
                    if(front == tem){
                        curr++;
                        pn.push(tem);
                        continue;
                    }
                    int ii = front.ff;
                    int jj = front.ss;
                    if(ii>0){
                        if(visited[ii-1][jj]==0&&graph[ii-1][jj]=='.'){
                            visited[ii-1][jj] = 1;
                            pn.push({ii-1,jj});
                        }
                    }if(ii<n-1){
                        if(visited[ii+1][jj]==0&&graph[ii+1][jj]=='.'){
                            visited[ii+1][jj] = 1;
                            pn.push({ii+1,jj});
                        }
                    }
                    if(jj>0){
                        if(visited[ii][jj-1]==0&&graph[ii][jj-1]=='.'){
                            visited[ii][jj-1] = 1;
                            pn.push({ii,jj-1});
                        }
                    }if(jj<m-1){
                        if(visited[ii][jj+1]==0&&graph[ii][jj+1]=='.'){
                            visited[ii][jj+1] = 1;
                            pn.push({ii,jj+1});
                        }
                    }
                }
                ans = max(ans,curr);
            }
        }
    }
    cout<<ans;
}

Measured memory_bytes: 256