/*
 _____ ____ _____   ___   ___   ___   ___ 
|_   _/ __ \_   _| |__ \ / _ \ |__ \ / _ \
  | || |  | || |      ) | | | |   ) | | | |
  | || |  | || |     / /| | | |  / /| | | |
 _| || |__| || |_   / /_| |_| | / /_| |_| |
|_____\____/_____| |____|\___/ |____|\___/ 
*/
#include <bits/stdc++.h>
#include <fstream>
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define per(i, a, b) for (int i = (a); i > (b); i--)
#define a(x) (x.begin(), x.end())
#define ar(x) (x.rbegin(), x.rend())
#define pb push_back
#define Pb() pop_back()
#define ll long long int
#define ull unsigned long long int
#define pii pair<int, int>
#define pll pair<ll, ll>
#define sc scanf
#define scin(x) sc("%d", &(x))
#define scln(x) sc("%lld", &(x))
#define pf prllf
#define ms(a, b) memset(a, b, sizeof(a))
#define mp make_pair
#define db double
#define EPS 10E-10
#define ff first
#define ss second
#define sqr(x) (x) * (x)
#define vi vector<int>
#define vl vector<ll>
#define vii vector<vector<int>>
#define vll vector<vector<ll>>
#define DBG pf("HI\n")
#define MOD 1000000007
#define CIN                       \
    ios_base::sync_with_stdio(0); \
    cin.tie(0);                   \
    cout.tie(0)
#define RUN_CASE(t, T) for (__typeof(t) t = 1; t <= T; t++)
#define CASE(t) prllf("Case %d: ", t)
#define CASEL(t) prllf("Case %d:\n", t)
#define intlimit 2147483647
#define longlimit 9223372036854775807
#define infinity (1 << 28)
#define gcd(a, b) __gcd(a, b)
#define lcm(a, b) ((a) * (b) / gcd(a, b))
#define PI 2 * acos(0.0)
// assert(x==y); gives run time when false
using namespace std;
int main()
{
    CIN;
    int n, m;
    cin >> n >> m;
    vector<vector<char>> v(n, vector<char>(m));
    vector<pair<int, int>> klo;
    rep(i, 0, n)
    {
        rep(j, 0, m)
        {
            cin >> v[i][j];
            if (v[i][j] == '.')
            {
                klo.pb({i, j});
            }
        }
    }
    int zg = klo.size(), maxi = 0;
    if(zg==n*m){
        cout << n+m-2;
        return 0;
    }
    set<pair<int, int>> vis;
    rep(i, 0, zg)
    {
        if (!vis.count(klo[i]))
        {
            pair<int,int>temp;
            queue<pair<int, pair<int, int>>> q;
            q.push({1, klo[i]});
            set<pair<int,int>>visi;
            while (!q.empty())
            {
                if(maxi<q.front().ff){
                    temp = q.front().ss;
                }
                maxi = max(maxi, q.front().ff);
                int a = q.front().ff, b = q.front().ss.ff, c = q.front().ss.ss;
                visi.insert({b, c});
                if (!visi.count({b + 1, c}) && b < n - 1 && v[b + 1][c] == '.')
                {
                    q.push({a + 1, {b + 1, c}});
                }
                if (!visi.count({b - 1, c}) && b > 0 && v[b - 1][c] == '.')
                {
                    q.push({a + 1, {b - 1, c}});
                }
                if (!visi.count({b, c + 1}) && c < m - 1 && v[b][c + 1] == '.')
                {
                    q.push({a + 1, {b, c + 1}});
                }
                if (!visi.count({b, c - 1}) && c > 0 && v[b][c - 1] == '.')
                {
                    q.push({a + 1, {b, c - 1}});
                }
                q.pop();
            }
            q.push({1,temp});
            while (!q.empty())
            {
                if(maxi<q.front().ff){
                    temp = q.front().ss;
                }
                maxi = max(maxi, q.front().ff);
                int a = q.front().ff, b = q.front().ss.ff, c = q.front().ss.ss;
                visi.insert({b, c});
                if (!visi.count({b + 1, c}) && b < n - 1 && v[b + 1][c] == '.')
                {
                    q.push({a + 1, {b + 1, c}});
                }
                if (!visi.count({b - 1, c}) && b > 0 && v[b - 1][c] == '.')
                {
                    q.push({a + 1, {b - 1, c}});
                }
                if (!visi.count({b, c + 1}) && c < m - 1 && v[b][c + 1] == '.')
                {
                    q.push({a + 1, {b, c + 1}});
                }
                if (!visi.count({b, c - 1}) && c > 0 && v[b][c - 1] == '.')
                {
                    q.push({a + 1, {b, c - 1}});
                }
                q.pop();
            }
        }
    }
    cout << maxi - 1;
}


Measured memory_bytes: 256