#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<queue>
#include<climits>
#include<cmath>
#include<sstream>
#include<iomanip>
#include <map>
#include <stack>

const int cc = pow( 10, 9 ) + 7;

bool sort_pair( std::pair< char, int > origin, std::pair< char, int > another )
{
    return origin.second > another.second;
}

int main()
{
    int a,b,c,d;
    std::cin>> a;
    std::cin>> b;

    std::vector< std::string > meiro;
    std::string aa;

    for( int i = 0; i < a; i++ )
    {
        std::cin>> aa;
        meiro.push_back( aa );
    }

    int max = -1;

    for( int i = 0; i < a; i++ )
    {
        std::queue< std::pair< std::pair< int, int >, int > > list;
        
        for( int r = 0; r < b; r++ )
        {
            if( meiro[i][r] != '#' )
            {
                std::vector< std::string > check_meiro = meiro;
                std::pair< std::pair< int, int >, int > check;
                check.first.first = i;
                check.first.second = r;
                check.second = 0;
                list.push( check );
                //std::cout<< "------" <<"\n";
                
                while( ! list.empty() )
                {
                    std::pair< std::pair< int, int >, int > current = list.front();
                    list.pop();

                    if( check_meiro[current.first.first][current.first.second] == '#' )
                    {
                        continue;
                    }
                    
                    check_meiro[current.first.first][current.first.second] = '#';
                    //std::cout<< current.first.first << " " << current.first.second << " " << current.second << " " << list.size() <<"\n";
                    
                    if( max < current.second )
                    {
                        max = current.second;
                        //std::cout<< current.second <<"\n";
                    }
                    
                    int up = std::max( 0, current.first.first - 1 );
                    int down = std::min( a-1, current.first.first + 1 );
                    int right = std::max( 0, current.first.second - 1 );
                    int left = std::min( b-1, current.first.second + 1 );

                    if( check_meiro[up][current.first.second] != '#' )
                    {
                        check.first.first = up;
                        check.first.second = current.first.second;
                        check.second = current.second + 1;
                        list.push( check );
                    }


                    if( check_meiro[down][current.first.second] != '#' )
                    {
                        check.first.first = down;
                        check.first.second = current.first.second;
                        check.second = current.second + 1;
                        list.push( check );
                        //std::cout<< down << " " << r << "\n";
                    }

                    
                    if( check_meiro[current.first.first][right] != '#' )
                    {
                        check.first.first = current.first.first;
                        check.first.second = right;
                        check.second = current.second + 1;
                        list.push( check );
                    }

                    if( check_meiro[current.first.first][left] != '#' )
                    {
                        check.first.first = current.first.first;
                        check.first.second = left;
                        check.second = current.second + 1;
                        list.push( check );
                    }
                }
            }
        }
    }

    std::cout<< max;
}


Measured memory_bytes: 256