/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include <iostream>
#include <fstream>

#include <iostream>
#include "bits/stdc++.h"

using namespace std;

typedef unsigned long long ll;
typedef int integer;
#define int                     long long
#define ii                      pair<int,int>
#define vii                     vector<pair<int,int>>
#define vi                      vector<int>
#define vvi                     vector<vector<int>>
#define f(a, b, c)                for(int a=b;a<c;a++)
#define s(x)                    in>>x
#define s2(x, y)                 in>>x>>y
#define s3(x, y, z)               in>>x>>y>>z
#define s4(x, y, z, w)             in>>x>>y>>z>>w
#define p(x)                    out<<x<<endl
#define p2(x, y)                 out<<x<<" "<<y<<endl
#define pl(x)                   out<<x
#define p2l(x, y)                out<<x<<" "<<y
#define p1d(a, n)                for(int ix=0;ix<n;ix++) out<<a[ix]<<" "; out<<endl
#define p2d(a, n, m)              for(int ix=0;ix<n;ix++){ for(int jx=0;jx<m;jx++) out<<a[ix][jx]<<" "; out<<endl;}
#define range(v)                v.begin(),v.end()
#define w(x)                    while(x--)
#define rst(x)                  memset(x, -1, sizeof(x))
#define UNVISITED               -1
#define VISITED                 0
#define EXPLORED                2
int rr[] = {1, 0, -1, 0};
int rc[] = {0, 1, 0, -1};

char grid[27][27];
int dist[400][400];

class DMazeMaster {
public:
    void solve(std::istream &in, std::ostream &out) {
        int h, w;
        s2(h, w);
        f(i, 0, 400)f(j, 0, 400) {
                dist[i][j] = 1e9;
            }
        f(i, 0, h)
            f(j, 0, w) {
                s(grid[i][j]);
                if (grid[i][j] == '.') {
                    int u = i * w + j;
                    dist[u][u] = 0;
                    f(k, 0, 4) {
                        int x = i + rr[k];
                        int y = j + rc[k];
                        if (x >= 0 && x < h && y >= 0 && y < w && grid[x][y] == '.') {
                            int v = x * w + y;
                            dist[u][v] = 1;
                            dist[v][u] = 1;
                        }
                    }
                }
            }
        int V = h * w;
        for (int k = 0; k < V; k++) {
            // Pick all vertices as source one by one
            for (int i = 0; i < V; i++) {
                // Pick all vertices as destination for the
                // above picked source
                for (int j = 0; j < V; j++) {
                    // If vertex k is on the shortest path from
                    // i to j, then update the value of dist[i][j]
                    if (dist[i][k] + dist[k][j] < dist[i][j])
                        dist[i][j] = dist[i][k] + dist[k][j];
                }
            }
        }
        int maxx = -1;
        ii better;
        f(i, 0, V)
            f(j, 0, V)
                if (dist[i][j] < 1e9) {
                    if (dist[i][j] > maxx) better = make_pair(i, j);
                    maxx = max(maxx, dist[i][j]);
                };
        out << maxx << endl;

    }
};


integer main() {
	DMazeMaster solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
}


Measured memory_bytes: 1536