#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <algorithm>
#include <cmath>
#include <ios>
#include <ctype.h>
#include <stack>
#include <istream>
#include <stdio.h>
#include <map>
#include <set>
#include <queue>
#include <unordered_map>
#include <functional>
#include <bitset>
#include <list>
#include <deque>
#include <time.h>
#include <random>
#include <iomanip>
#include <fstream>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define REP(i,a,b) for (int i = a; i < (b); ++i)
#define RREP(i,a,b) for (int i = a; i > (b); --i)
#define all(x) (x).begin(),(x).end()
const long long INF = 1000000007;
typedef long long ll;
using namespace std;
using Graph = vector<vector<int>>;
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; }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { return (a * b) / gcd(a,b); }
int bfs(Graph &G,int sx, int sy){
  vector<int>dist(10000,-1);
  queue<int>que;
  int n = (sy * w) + sx;
  dist[n] = 0;
  que.push(n);
  while(!que.empty()){
    int v = que.front();
    que.pop();
    for(auto nv : G[v]){
      if(dist[nv] != -1)continue;
      dist[nv] = v + 1;
      que.push(nv);
    }
  }
  int res = 0;
  rep(i,1000)res = max(res,dist[i]);
  return res;
}
int h,w;
int solve(){
  cin >> h >> w;
  Graph G(h * w);
  vector<string>s(h + 1);
  rep(i,h){
    string tmp;
    cin >> tmp;
    tmp.push_back('#');
    s[i] = tmp;
  }
  string tmp;
  rep(i,w)tmp.push_back('#');
  s[h] = tmp;
  rep(i,h)rep(j,w){
    if(s[i][j] == '#')continue;
    int now = (i * w) + j;
    if(s[i + 1][j] != '#'){
      G[now].push_back(now + w);
      G[now + w].push_back(now);
    }
    if(s[i][j + 1] != '#'){
      G[now + 1].push_back(now);
      G[now].push_back(now + 1);
    }
  }
  int ans = 0;
  rep(i,h)rep(j,w){
    if(s[i][j] == '#')continue;
    ans = max(ans,bfs(G,i,j));
  }
  cout << ans << endl;
  return 0;
}
int main(){
  ios::sync_with_stdio(false);cin.tie(nullptr);
  // cout << fixed;cout << setprecision(16);
  solve();
  return 0;
}