#include <bits/stdc++.h>

#define M_PI 3.14159265358979323846

using namespace std;

//typedef
//-------------------------#include <bits/stdc++.h>

#define M_PI 3.14159265358979323846

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();
}
inline int readInt()
{
    int x;
    scanf("%d", &x);
    return x;
}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<int, PII> TIII;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;

//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 SQ(a) ((a) * (a))
#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, s, n) for (int i = s; i < (int)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define MOD 1000000007

#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define trav(a, x) for (auto &a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
const double EPS = 1E-8;

#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
const int INF = 2147483647;

const int dxy[5] = {-1, 0, 1, 0, -1};
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    //cout << fixed << setprecision(10);

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

    vector<string> f;
    for (int i = 0; i < H; i++)
    {
        string s;
        cin >> s;
        f.push_back(s);
    }
    int ans = 0;
    for (int i = 0; i < H; i++)
    {
        for (int j = 0; j < W; j++)
        {
            if (f[i][j] == '#')
                continue;

            vector<vector<int>> d(H, vector<int>(W, -1));
            queue<pair<int, int>> q;

            q.push(make_pair(i, j));
            d[i][j] = 0;

            while (q.size())
            {
                pair<int, int> p = q.front();
                q.pop();

                int y = p.first, x = p.second;

                for (int k = 0; k < 4; k++)
                {
                    int ny = y + dxy[k], nx = x + dxy[k + 1];

                    if (ny >= 0 && ny < H && nx >= 0 && nx < W && d[ny][nx] == -1 && f[ny][nx] == '.')
                    {
                        d[ny][nx] = d[y][x] + 1;
                        q.push(make_pair(ny, nx));
                    }
                }
            }

            for (int k = 0; k < H; k++)
            {
                for (int l = 0; l < W; l++)
                {
                    ans = max(ans, d[k][l]);
                }
            }
        }
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256