/// Containers Start
#include <algorithm>
#include <bitset>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
/// C Header Files
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <math.h>
#include <stdio.h>
/// Containers End

using namespace std;

/// Math Start
#define PI acos(-1.0)
#define Pi 3.141592653589793
#define EPS (1e-7)
#define INF (0x3f3f3f3f)
// #define INF 9e+18

/// Math End

/// Extra Start
#define nn '\n'
#define pb push_back
#define ull unsigned long long
#define ll long long
#define MOD 1000000007
#define sz(a) int((a).size())
#define space " "
#define All(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
/// Extra End

#define rep(i, n) for (int i = 0; i < n; i++)
#define Cini(a)                                                                \
    int a;                                                                     \
    cin >> a;
#define Cinii(a, b)                                                            \
    int a, b;                                                                  \
    cin >> a >> b;
#define Ciniii(a, b, c)                                                        \
    int a, b, c;                                                               \
    cin >> a >> b >> c;
#define Cins(s)                                                                \
    string s;                                                                  \
    cin >> s;
#define Cinss(s1, s2)                                                          \
    string s1, s2;                                                             \
    cin >> s1 >> s2;
#define Cinc(c)                                                                \
    char c;                                                                    \
    cin >> c;
/// Functions End

/// Debug Start
#define deb(x) cout << #x << ": " << x << endl
#define deb2(x, y) cout << #x << ": " << x << '\t' << #y << ": " << y << endl;
#define deb3(x, y, z)                                                          \
    cout << #x << ": " << x << '\t' << #y << ": " << y << '\t' << #z << ": "   \
         << z << endl;
/// Debug End

int dx[] = {-1, 0, 1, 0};
int dy[] = {0, -1, 0, 1};
// int dx[] = {-1, 0, 1};
// int dy[] = {-1, 0, 1};

/**>>>>>>>>>>>>>>>>>>> END <<<<<<<<<<<<<<<<<<**/

/// template

class DirectedGraph {
public:
    int V;
    vector<vector<int> > costs; //0-indexed

    DirectedGraph(int v) : V(v), costs(v, vector<int>(v, INF)) {
        for (int i = 0; i < V; i++) {
            costs[i][i] = 0;
        }
    }

    void add_edge(int u, int v, int cost) {
        costs[u][v] = cost;
    }

    void warshall_floyd() {
        for (int k = 0; k < V; k++) {
            for (int i = 0; i < V; i++) {
                for (int j = 0; j < V; j++) {
                    if(costs[i][k]!=INF && costs[k][j]!=INF) costs[i][j] = min(costs[i][j], costs[i][k] + costs[k][j]);
                }
            }
        }
    }
};


signed main(void) {
    cin.sync_with_stdio(false);
    cin.tie(0);
    Cinii(H, W);
    vector<string > S(H);
    rep(i, H) cin >> S[i];
    DirectedGraph g = DirectedGraph(H*W);
    rep(y,H)rep(x,W){
        rep(i,4){
            int nx = x + dx[i],ny = y + dy[i];
            if(nx<0 || nx>=W || ny<0 || ny>=H) continue;
            if(S[y][x]=='#' || S[ny][nx]=='#'){
                g.add_edge(y * W + x, ny * W + nx, INF);
                g.add_edge(ny * W + nx, y * W + x, INF);
            }else{
                g.add_edge(y * W + x, ny * W + nx, 1);
                g.add_edge(ny * W + nx, y * W + x, 1);
            }
        }
    }
    g.warshall_floyd();
    int ansMax = 0;
    rep(y, H) rep(x, W) {
        rep(ny,H)rep(nx,W){
            int cost = g.costs[y * W+ x][ny * W + nx];
            if (cost == INF)
                continue;
            ansMax = max(ansMax, cost);
        }
    }
    cout << ansMax << nn;
    return 0;
}


Measured memory_bytes: 896