#include<bits/stdc++.h>
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repR(i,n) for(ll i=n;i>=0;i--)
#define all(v)(v).begin(),(v).end()
#define rall(v)(v).rbegin(),(v).rend()
#define F first
#define S second
#define pb push_back
#define pu push
#define COUT(x) cout<<(x)<<endl
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,vector<ll>,greater<ll>>
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define mp make_pair
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define sz(x) (int)(x).size()
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(int)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(int)(key)))
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll MOD = 1000000007LL;
const ll INF = 1LL << 60;
using vll = vector<ll>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvll = vector<vll>;
using vstr = vector<string>;
using pll = pair<ll, ll>;
const int di[]={0,-1,0,1};
const int dj[]={-1,0,1,0};
int main(){
  ll h,w;
  cin>>h>>w;
  vstr ta(h);
  ll ans=0;
  rep(i,h) cin>>ta[i];
  rep(si,h) rep(sj,w){
    if(ta[si][sj]=='#') continue;
    vvll dist(h,vll(w,INF));
    queue<pll> q;
    auto j[&]=(ll i,ll j,ll x){
      if(dist[i][j]!=INF) return;
      dist[i][j]=x;
      q.pb(pll(i,j));
    }
    j(si,sj,0);
    while(!q.empty()){
      ll i=q.front().F;
      ll j=q.front().S;
      q.pop();
      rep(dir,4){
        ll ni=i+di[dir],nj=j+dj[i];
        if(ni<0||ni>=h||nj<0||nj>=w) continue;
        if(ta[ni][nj]=='#') continue;
        j(ni,nj,dist[i][j]+1);
      }
    }
    rep(i,h)rep(j,w){
      if(ta[i][j]=='#') continue;
      ans=max(ans,ta[i][j]);
    }
  }
  COUT(ans);
}
