///cREATED bY BERNARB.01
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef tree<int,null_type,less<int>,rb_tree_tag, tree_order_statistics_node_update> indexed_set;
typedef priority_queue<int,vector<int>,greater<int>> pqil;
typedef priority_queue<int> pqig;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
typedef priority_queue<pii> pqiig;
typedef vector<pii> vii;
typedef vector<piii> viii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
typedef map<int, int> mii;
#define mid ((l+r)/2)
#define PB push_back
#define PP pop_back
#define PF push_front
#define DF pop_front
#define F first
#define S second
#define MP make_pair
#define C continue
#define B break
#define R return
#define sz(v) (int)(v).size()
#define len(s) (int)(s).length()
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define clr(arr, x) memset((arr), (x), sizeof (arr))
#define loop(n) for(int i=0; i<(n); i++)
#define jloop(n) for(int j=0; j<(n); j++)
#define rloop(n) for(ll i=(n)-1; i>=0; i--)
const ll N = 2e5+9;
const ll INF = 2e17+423;
const ll mod = 1e9+7; //998244353;
const ld pi = acos(-1.0);
const ld cmpf = 1e-9;
//__int128_t
#define endl '\n'
ll h, w;
char a[30][30];
vi ed[900];
ll bfs(ll node){
  queue<ll> q;
  ll ret = 0;
  bool vis[201];
  ll dis[201];
  clr(vis, 0);
  q.push(node);
  dis[node]=0;
  while(!q.empty()){
    ll u = q.front(); q.pop();
    vis[u]=1;
    for(auto v : ed[u])if(!vis[v]){
      dis[v] = dis[u]+1;
      ret = max(ret, dis[v]);
      q.push(v);
    }
  }
  R ret;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> h >> w;
  loop(h)
    jloop(w)
      cin >> a[i][j];
  ll c = 0;
  for(ll i=0; i<h; i++){
    for(ll j=0; j<w; j++){
      ++c;
      if(a[i][j]=='#') C;
      if(i>0) if(a[i-1][j]=='.') ed[c].PB(c-w);
      if(j>0) if(a[i][j-1]=='.') ed[c].PB(c-1);
      if(i<h-1) if(a[i+1][j]=='.') ed[c].PB(c+w);
      if(j<w-1) if(a[i][j+1]=='.') ed[c].PB(c+1);
      if(c==h*w) B;
    }
    if(c==h*w) B;
  }
  ll ans = 0;
  for(ll i=1; i<=w*h; ++i)
    ans = max(ans, bfs(i));
  cout << ans  <<endl;
  R 0;
}
