package main

import (
	"fmt"
)

func main() {
	var h, w int
	fmt.Scan(&h)
	fmt.Scan(&w)

	var currentx, currenty int
	currentx = -1
	currenty = -1

	var meiro [][]string
	var distance [][]int
	meiro = make([][]string, h)
	distance = make([][]int, h)
	for i := 0; i < h; i++ {
		meiro[i] = make([]string, w)
		distance[i] = make([]int, w)
		var line string
		fmt.Scan(&line)
		for j := 0; j < w; j++ {
			if line[j:j+1] == "." && currentx == -1 {
				currentx = j
				currenty = i
				distance[i][j] = 0
			} else {
				distance[i][j] = -1
			}
			meiro[i][j] = line[j : j+1]
		}
	}

	// どこかから最短経路を計算する
	// 一番遠いところを始点にして再計算して一番遠いところの距離
	distance = adj(currenty, currentx, 0, meiro, distance, h, w)
	maxD := 0
	maxX := 0
	maxY := 0
	for i := 0; i < h; i++ {
		for j := 0; j < w; j++ {
			if distance[i][j] > maxD {
				maxD = distance[i][j]
				maxY = i
				maxX = j
			}
			distance[i][j] = -1
		}
	}
	distance[maxY][maxX] = 0

	distance = adj(maxY, maxX, 0, meiro, distance, h, w)

	for i := 0; i < h; i++ {
		for j := 0; j < w; j++ {
			if distance[i][j] > maxD {
				maxD = distance[i][j]
			}
		}
	}

	fmt.Println(maxD)
}

func adj(y, x, now int, meiro [][]string, distance [][]int, h, w int) [][]int {
	if y+1 < h && meiro[y+1][x] == "." && (distance[y+1][x] == -1 || distance[y+1][x] > now+1) {
		distance[y+1][x] = now + 1
		distance = adj(y+1, x, now+1, meiro, distance, h, w)
	}
	if y-1 >= 0 && meiro[y-1][x] == "." && (distance[y-1][x] == -1 || distance[y-1][x] > now+1) {
		distance[y-1][x] = now + 1
		distance = adj(y-1, x, now+1, meiro, distance, h, w)
	}
	if x+1 < w && meiro[y][x+1] == "." && (distance[y][x+1] == -1 || distance[y][x+1] > now+1) {
		distance[y][x+1] = now + 1
		distance = adj(y, x+1, now+1, meiro, distance, h, w)
	}
	if x-1 >= 0 && meiro[y][x-1] == "." && (distance[y][x-1] == -1 || distance[y][x-1] > now+1) {
		distance[y][x-1] = now + 1
		distance = adj(y, x-1, now+1, meiro, distance, h, w)
	}

	return distance
}
