#include<bits/stdc++.h>
using namespace std;

#define rep(i,n) for(ll i = 0; i < n; i++)
#define per(i,n) for(ll i = n-1; i >= 0; i--)
#define REP(i,n) for(ll i = 1; i < n; i++)
#define PER(i,n) for(ll i = n; i >= 1; i--)
#define sz(x) int(x.size())
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define YesorNo(a) printf(a ? "Yes\n" : "No\n")
#define endl '\n'
#define fi first
#define se second
using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
using vi = vector<int>;
using vii = vector<vi>;
using vl = vector<ll>;
using vll = vector<vl>;
using vs = vector<string>;
using vb = vector<bool>;
using vc = vector<char>;
using vcc = vector<vc>;
using vP = vector<P>;
using vPP = vector<vP>;
using vPl = vector<Pl>;
const int dx[] = {0,1,0,-1,1,1,-1,-1};
const int dy[] = {1,0,-1,0,1,-1,-1,1};
const int inf = (1<<30)-1;
const ll infll = (1LL<<62)-1;
ll ceil(const ll &a, const ll &b){return ((a)+(b)-1)/b;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }



int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  int h, w;
  cin >> h >> w;
  vs s(h);
  rep(i,h) cin >> s[i];
  int ans = 0;          vector<vb> seen(h,vb(w));
  rep(i,h) {
    rep(j,w) {
      rep(k,h) {
        rep(l,w) {
          if(s[i][j] == '#' || s[k][l] == '#') continue;
          vii d(h,vi(w));
          queue<P> q;
rep(y,h)rep(x,w)seend[y][x]=0;
          q.emplace(i,j);
          d[i][j] = 0;
          while(sz(q)) {
            int y = q.front().fi;
            int x = q.front().se;
            q.pop();
            seen[y][x] = true;
            rep(dis,4) {
              int ny = dy[dis] + y;
              int nx = dx[dis] + x;
              if(ny < 0 || ny >= h || nx < 0 || nx >= w) continue;
              if(s[ny][nx] == '#' || seen[ny][nx]) continue;
              d[ny][nx] = d[y][x] + 1;
              q.emplace(ny,nx);
            }
          }
          chmax(ans, d[k][l]);
        }
      }
    }
  }
  cout << ans << endl;
}
