import java.util.Scanner

fun main(args: Array<String>) {
	val scn = Scanner(System.`in`)
	var h = scn.nextInt()
	var w = scn.nextInt()
	var maze = Array(h){
		scn.next().toCharArray().map{ c -> c=='.' }.toBooleanArray()
	}
	if (w>h){
		maze = Array(w){ i -> BooleanArray(h) {j -> maze[j][i]} }
		val tmp = w; w = h; h = tmp
	}
	var ans = 0
	for (i in 0 until h){
		for (j in 0 until w){
			if (!maze[i][j]) continue
			ans = Math.max(ans, max_dist(maze, Pair(i, j)))
		}
	}
	print(ans)
}

fun max_dist(maze: Array<BooleanArray>, from: Pair<Int, Int>): Int{
	val map = Array(maze.size){i -> IntArray(maze[0].size){ j -> if (maze[i][j]) -1 else -2 } }
	map[from.first][from.second] = 0
	var list = listOf(from)
	val side = arrayOf(Pair(-1, 0), Pair(0, -1), Pair(0, 1), Pair(1, 0))
	while (list.size!=0){
		val nextList = mutableListOf<Pair<Int, Int>>()
		for ((r, c) in list){
			for ((dy, dx) in side){
				val (nr, nc) = Pair(r+dy, c+dx)
				if (nr in maze.indices && nc in maze[0].indices){
					if (map[nr][nc]==-1){
						map[nr][nc] = map[r][c]+1
						nextList.add(Pair(nr, nc))
					}
				}
			}
		}
		list = nextList
	}
	return map.map{it.max()!!}.max()!!
}