using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;
using static System.Math;

namespace CSharpSpiral {
	class Program {
		static void Main(string[] args) {
			var sw = new StreamWriter(Console.OpenStandardOutput()) {
				AutoFlush=
#if DEBUG
			true
#else
			false
#endif
			};
			Console.SetOut(sw);
			new Program().Solve(new ConsoleInput(
#if DEBUG
			new StreamReader("../../../inputData.txt")
#else
			Console.In
#endif
			, ' '));
			Console.Out.Flush();
		}
		public void Solve(ConsoleInput cin) {
			var H = cin.ReadInt;
			var W = cin.ReadInt;
			var S = new bool[H, W];
			var G = new Graph(H*W);
			for(int i = 0; i<H; i++) {
				var line = cin.ReadLine;
				for(int j = 0; j<W; j++) {
					S[i, j]=line[j]=='.'; 
				}
			}
			for(int i = 0; i<H-1; i++) {
				for(int j = 0; j<W; j++) {
					var point = i*W+j;
					if(S[i, j]&&S[i+1, j]) {
						G.AddEdge(point, point+W, 1);
						G.AddEdge(point+W, point, 1);
					}
				}
			}
			for(int i = 0; i<H; i++) {
				for(int j = 0; j<W-1; j++) {
					var point = i*W+j;
					if(S[i, j]&&S[i, j+1]) {
						G.AddEdge(point, point+1, 1);
						G.AddEdge(point+1, point, 1);
					}
				}
			}
			var L = G.WarshallFloyd();
			var res = 0L;
			for(int i = 0; i<H*W; i++) {
				for(int j = 0; j<H*W; j++) {
					if((L[i, j]??-1)>res) 
						res=(long)L[i, j];
				}
			}
			Console.WriteLine(res);
		}
	}
	static class ExtendClass {
		public static string Join<T>(this IEnumerable<T> X, string separator = " ") => string.Join(separator, X);
		public static void MergeSort<T>(this T[] A, bool desending) where T : IComparable<T> {
			if(desending)
				MergeSort(A, Comparer<T>.Create((x, y) => y.CompareTo(x)));
			else
				MergeSort(A, Comparer<T>.Create((x, y) => x.CompareTo(y)));
		}
		public static void MergeSort<T>(T[] A, IComparer<T> comparer) where T : IComparable<T> {
			MergeSort1(0, A.Length, A, comparer);
		}
		private static void Merge<T>(int left, int mid, int right, T[] A, IComparer<T> comparer)
			where T : IComparable<T> {
			var nl = mid-left;
			var nr = right-mid;
			var L = new T[nl];
			var R = new T[nr];
			for(int i = 0; i<nl; i++)
				L[i]=A[i+left];
			for(int i = 0; i<nr; i++)
				R[i]=A[i+mid];
			int il = 0, ir = 0;
			for(int k = left; k<right; k++) {
				if(comparer.Compare(L[il], R[ir])<=0) {
					A[k]=L[il++];
					if(il==nl) {
						k++;
						for(; ir<nr;)
							A[k++]=R[ir++];
						break;
					}
				} else {
					A[k]=R[ir++];
					if(ir==nr) {
						k++;
						for(; il<nl;)
							A[k++]=L[il++];
						break;
					}
				}
			}
		}
		private static void MergeSort1<T>(int left, int right, T[] A, IComparer<T> comparer)
		where T : IComparable<T> {
			if(left+1<right) {
				var mid = (left+right)/2;
				MergeSort1(left, mid, A, comparer);
				MergeSort1(mid, right, A, comparer);
				Merge(left, mid, right, A, comparer);
			}
		}
	}
	class ConsoleInput {
		private readonly TextReader _stream;
		private readonly char _separator = ' ';
		private readonly Queue<string> inputStream;
		public ConsoleInput(TextReader stream, char separator = ' ') {
			this._separator=separator;
			this._stream=stream;
			inputStream=new Queue<string>();
		}
		public string Read {
			get {
				if(inputStream.Count!=0) return inputStream.Dequeue();
				string[] tmp = _stream.ReadLine().Split(_separator);
				for(int i = 0; i<tmp.Length; ++i)
					inputStream.Enqueue(tmp[i]);
				return inputStream.Dequeue();
			}
		}
		public string ReadLine { get { return _stream.ReadLine(); } }
		public int ReadInt { get { return int.Parse(Read); } }
		public long ReadLong { get { return long.Parse(Read); } }
		public double ReadDouble { get { return double.Parse(Read); } }
		public string[] ReadStrArray(long N) {
			var ret = new string[N];
			for(long i = 0; i<N; ++i)
				ret[i]=Read;
			return ret;
		}
		public int[] ReadIntArray(long N) { var ret = new int[N]; for(long i = 0; i<N; ++i) ret[i]=ReadInt; return ret; }
		public long[] ReadLongArray(long N) { var ret = new long[N]; for(long i = 0; i<N; ++i) ret[i]=ReadLong; return ret; }
		public double[] ReadDoubleArray(long N) { var ret = new double[N]; for(long i = 0; i<N; ++i) ret[i]=ReadDouble; return ret; }
		public bool isEOF {
			get { return _stream.Peek()==-1; }
		}
	}
	class Graph: Graph<long> {
		public Graph(int _N) : base(_N) { }
		public long?[,] WarshallFloyd() {
			var matrix = new long?[N, N];
			for(int i = 0; i<N; i++) {
				for(int j = 0; j<N; j++) {
					if(i==j) matrix[i, j]=0;
					else if(Edges[i].ContainsKey(j))
						matrix[i, j]=Edges[i][j];
					else matrix[i, j]=null;
				}
			}
			for(int k = 0; k<N; k++) {
				var tmp = new long?[N, N];
				for(int i = 0; i<N; i++) {
					for(int j = 0; j<N; j++) {
						var far = matrix[i, k]+matrix[k, j];
						tmp[i, j]=far==null ? matrix[i, j] : matrix[i, j]==null ? far :
						Nullable.Compare(far, matrix[i, j])>0 ? matrix[i, j] : far;
					}
				}
				matrix=tmp;
			}
			return matrix;
		}
	}
	class Graph<T> {
		public readonly int N;
		public T[] Nodes { get; }
		protected List<int>[] Nexts { get; }
		protected Dictionary<int, T>[] Edges { get; set; }
		public Graph(int _N) {
			N=_N;
			Nodes=new T[_N];
			Nexts=new List<int>[_N];
			Edges=new Dictionary<int, T>[_N];
			for(int i = 0; i<_N; i++) {
				Nexts[i]=new List<int>();
				Edges[i]=new Dictionary<int, T>();
			}
		}
		public void Update(int i, T value) {
			Nodes[i]=value;
		}
		public void AddEdge(int from, int to, T value) {
			Edges[from].Add(to, value);
			Nexts[from].Add(to);
		}
		private void PointDFS(int from, Action<int> onEnter, Action<int> onLeave) {
			var S = new Stack<int>();
			S.Push(from);
			var entered = new bool[N];
			var departed = new bool[N];//dep<=ent
			var childCount = new int[N];
			while(S.Any()) {
				var v = S.Peek();
				if(!entered[v]) {
					onEnter?.Invoke(v);
					entered[v]=true;
				}
				for(int i = childCount[v]; i<Nexts[v].Count; i++) {
					if(!entered[Nexts[v][i]]) {
						S.Push(Nexts[v][i]);
						childCount[v]=i+1;
						goto NextLoop;
					}
				}
				S.Pop();
				childCount[v]=Nexts[v].Count;
				if(!departed[v]) {
					onLeave?.Invoke(v);
					departed[v]=true;
				}
			NextLoop:;
			}
		}
	}
}

Measured memory_bytes: 38556