#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <unordered_map>
using namespace std;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }

#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }

template<class T> vector<T> make_vec(size_t a) { return vector<T>(a); }
template<class T, class... Ts> auto make_vec(size_t a, Ts... ts) {
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
template<class T, class V>
typename enable_if<is_class<T>::value == 0>::type fill(T &t, const V &v) {
    t = v;
}
template<class T, class V>
typename enable_if<is_class<T>::value != 0>::type fill(T &t, const V &v){
    for (auto &e : t) fill(e, v);
}


const int MAX = 500;
const int INF = 1<<29;
int H, W;

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

int dp[MAX][MAX];

int id(int x, int y) {
    return x * W + y;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    while (cin >> H >> W) {
        for (int i = 0; i < MAX; ++i) {
            for (int j = 0; j < MAX; ++j) dp[i][j] = INF;
            dp[i][i] = 0;
        }

        vector<string> s(H);
        for (int i = 0; i < H; ++i) cin >> s[i];

        for (int x = 0; x < H; ++x) {
            for (int y = 0; y < W; ++y) {
                if (s[x][y] == '#') continue;
                int from = id(x, y);

                for (int dir = 0; dir < 4; ++dir) {
                    int nx = x + dx[dir], ny = y + dy[dir];
                    if (nx < 0 || nx >= H || ny < 0 || ny >= W) continue;
                    if (s[nx][ny] == '#') continue;
                    int to = id(nx, ny);

                    dp[from][to] = 1;
                    dp[to][from] = 1;
                }
            }
        }

        int V = H*W;
        for (int k = 0; k < V; ++k)
            for (int i = 0; i < V; ++i)
                for (int j = 0; j < V; ++j)
                    chmin(dp[i][j], dp[i][k] + dp[k][j]);

        int res = 0;
        for (int x = 0; x < H; ++x) {
            for (int y = 0; y < W; ++y) {
                int from = id(x, y);
                if (s[x][y] == '#') continue;
                for (int x2 = 0; x2 < H; ++x2) {
                    for (int y2 = 0; y2 < W; ++y2) {
                        int to = id(x2, y2);
                        if (s[x2][y2] == '#') continue;

                        chmax(res, dp[from][to]);
                    }
                }
            }
        }
        cout << res << endl;
                    
    }
}


















Measured memory_bytes: 1280