const input=require('fs').readFileSync('/dev/stdin','utf8').split(/[\s]/);let input_i=-1;const tn=():number=>{input_i++;return Number(input[input_i])};const tnn=(n:number):number[]=>{const a=[];for(let i=0;i<n;i++){a.push(tn())}return a};const ts=():string=>{input_i++;return String(input[input_i])};const tss=(n:number):string[]=>{const a=[];for(let i=0;i<n;i++){a.push(ts())}return a};const to=(...arg)=>{console.log(...arg)};const abs=(a)=>{return Math.abs(a)};const min=(...a)=>{return Math.min(...a)};const max=(...a)=>{return Math.max(...a)};const floor=(a)=>{return Math.floor(a)};const ceil=(a)=>{return Math.ceil(a)};const asc=(ar:number[])=>{const t=[...ar];return ar.sort((a,b)=>{return a-b})};const desc=(ar:number[])=>{const t=[...ar];return t.sort((a,b)=>{return b-a})};const sw=(a,arr:any[],op:'=='|'>='|'>'|'<='|'<'='==')=>{for(let i=0;i<arr.length-1;i+=2){if(eval(a+op+arr[i])){return arr[i+1]}}return arr[arr.length-1]};const near=(n:number,arr:number[]):number=>{let ne=arr[0],ni=0;for(let i=1;i<arr.length;i++){if(Math.abs(n-ne)>Math.abs(n-arr[i])){ne=arr[i];ni=i}}return ni};const deduplicate=(a:any[]):any[]=>{return Array.from(new Set(a))};const gcd=(x,y)=>{while(y){[x,y]=[y,x%y]}return x};const sum=(arr)=>{return arr.reduce((a,b)=>a+b);};const isPrime=(n:number):boolean=>{if(n<2)return false;const suq=Math.sqrt(n);for(let i=2;i<=suq;i++){if(n%i==0){return false;}}return true;};
const main=()=>{
  let [mh,mw]=tnn(2),map=new Array(mh),save=new Array(mh)
  let start=[-1]
  let dh=[0,0,-1,1]
  let dw=[1,-1,0,0]
  for(let i=0;i<mh;i++){
    map[i]=ts().split('')
    save[i]=new Array(mw)
    save[i].fill(-1)
    // 開始位置探す
    if(start[0]==-1){
      for(let j=0;j<mw;j++){
        if(map[i][j]=='.'){
          start=[i,j]
          break
        }
      }
    }
  }
  // 縦,横,カウンタ
  let maxnum=0
  for(let j=0;j<mh;j++){
    for(let k=0;k<mw;k++){
      let stack=[[j,k,1]]
      save[j][k]=0
      while(stack.length>0){
        let [h,w,c]=stack.shift()
        if(save[h][w]>maxnum){
          maxnum=save[h][w]
        }
        for(let i=0;i<4;i++){
          if(h+dh[i]<0 || h+dh[i]>=mh || w+dw[i]<0 || w+dw[i]>=mw || map[h+dh[i]][w+dw[i]]=='#')continue
          if(save[h+dh[i]][w+dw[i]]==-1){
            stack.push([h+dh[i], w+dw[i], c+1])
            save[h+dh[i]][w+dw[i]]=c
          }
        }
      }
      for(let i=0;i<mh;i++){
        save[i].fill(-1)
      }
    }
  }
  to(maxnum)
}
main()
