#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <string>
#include <cstring>
#include <sstream>
#include <cmath>
#include <functional>
#include <fstream>
#include <cstdlib>
typedef long long ll;
const int MOD = 1e9+7;


#define REP(i, N) for (int i = 0; i < (N); i++)
#define REPP(i, a, b) for (int i = (a); i < (b); i++)
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define VSORT(c) sort((c).begin(),(c).end())
#define SZ(x) ((int)(x).size())
//vvintを作る　マクロで　 #define vvint(N,M) vector<vector<int>>

using namespace std;


int main(){
    
    cin.tie(0);
    ios::sync_with_stdio(false);

    int H,W;
    cin >> H >> W;

    int maize[H+2][W+2],chain[H+2][W+2],state[H+2][W+2];
    for(int i = 0; i < H+2;i++){
        for(int l = 0; l < W+2;l++){
            maize[i][l] = 0;
            chain[i][l] = -1; 
            // 0 not visit ,1 visited
            state[i][l] = 1;
        }
    }

    string tmp;
    for(int i = 0; i < H;i++){
        cin >> tmp;
        for(int l = 0; l < W;l++){
            if(tmp[l] == '.'){
                maize[i+1][l+1] = 1;
                state[i+1][l+1] = 0;
            }else{
                maize[i+1][l+1] = 0;
            }
        }
    }
    int h=0,w=0;
    // bool ck = false;
    // for(int i = 0; i < H;i++){
    //     for(int l = 0; l < W;l++){
    //         int cnt = 0;
    //         if(maize[i+1][l+1] == 1){
    //             if(maize[i][l+1] == 1){
    //                 cnt++;
    //             }
    //             if(maize[i+1][l] == 1){
    //                 cnt++;
    //             }
    //             if(maize[i+2][l+1] == 1){
    //                 cnt++;
    //             }
    //             if(maize[i+1][l+2] == 1){
    //                 cnt++;
    //             }
    //         }
    //         chain[i+1][l+1] = cnt;
    //         if(cnt == 1){
    //             h = i;
    //             w = l;
    //             ck = true;
    //         }
    //         if(!ck){
    //             h = i;
    //             w = l;
    //         }
    //     }
    // }
    ll max = 0;
    for(int i = 0; i < H+2;i++){
        for(int l = 0; l < W+2;l++){
            
            
            if(maize[i][l] == 1){
                ll ans[H+2][W+2];
                for(int k = 0; k < H+2;k++){
                    for(int m = 0; m < W+2;m++){
                        ans[k][m] = 0;
                        state[k][m] = 0;
                    }
                }
                h = i-1;
                w = l-1;
                queue<pair<int,int> > que;
                que.push(make_pair(h,w));
                state[h+1][w+1] = 1;
                int tmph,tmpw;
                while(true){
                    bool next = false;
                    if(maize[h][w+1] == 1 && state[h][w+1] == 0){
                        next = true;
                        state[h][w+1] = 1;
                        tmph = h-1;tmpw = w;
                        ans[h][w+1] = ans[h+1][w+1]+1;
                    }else if(maize[h+1][w] == 1 && state[h+1][w] == 0){
                        next = true;
                        state[h+1][w] = 1;
                        tmph = h;tmpw = w-1;
                        ans[h+1][w] = ans[h+1][w+1]+1;
                    }else if(maize[h+2][w+1] == 1 && state[h+2][w+1] == 0){
                        next = true;
                        state[h+2][w+1] = 1;
                        tmph = h+1;tmpw = w;
                        ans[h+2][w+1] = ans[h+1][w+1]+1;
                    }else if(maize[h+1][w+2] == 1 && state[h+1][w+2] == 0){
                        next = true;
                        state[h+1][w+2] = 1;
                        tmph = h;tmpw = w+1;
                        ans[h+1][w+2] = ans[h+1][w+1]+1;
                    }
                    if(next){
                        que.push(make_pair(tmph,tmpw));
                    }else if(que.empty()){
                        break;   
                    }else{
                        pair<int,int> tmp = que.front();
                        que.pop();
                        h = tmp.first;
                        w = tmp.second;
                    }
                }
                for(int i = 0; i < H+1;i++){
                    for(int l = 0; l < W+1;l++){
                        if(max < ans[i][l]){
                            max = ans[i][l];
                        }
                    }
                }
                // for(int i = 0; i < H+2;i++){
                //     for(int l = 0; l < W+2;l++){
                //         cout << ans[i][l] << " ";
                //     }
                //     cout << endl;
                // }
                // cout << endl;
            }
        }
    }
    cout << max << endl;

    return 0;
}

Measured memory_bytes: 256