#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn get_index(x: usize, y: usize, w: usize) -> usize {
    x + y * w
}

fn main() {
    let v = read_vec::<usize>();
    let (h, w) = (v[0], v[1]);
    let mut grid = vec![vec![]; h];
    for i in 0..h {
        let s = read::<String>().chars().collect::<Vec<_>>();
        grid[i] = s;
    }

    let mut edges = vec![vec![INF; w * h]; w * h];
    for y in 0..h {
        for x in 0..w {
            if grid[y][x] == '#' {
                continue;
            }
            let idx = get_index(x, y, w);
            for (adj_x, adj_y) in get_adjacents(x, y, w, h) {
                let adj_idx = get_index(adj_x, adj_y, w);
                edges[idx][adj_idx] = 1;
            }
        }
    }
    let cost = warshall_floyd(w * h, edges);
    let mut ans = 0;
    for i in 0..w * h {
        for j in 0..w * h {
            if cost[i][j] >= INF {
                continue;
            }
            ans = max(ans, cost[i][j]);
        }
    }
    println!("{}", ans);
}

const INF: i64 = 1000000;

fn warshall_floyd(n: usize, mut edges: Vec<Vec<i64>>) -> Vec<Vec<i64>> {
    for k in 0..n {
        for i in 0..n {
            for j in 0..n {
                edges[i][j] = std::cmp::min(edges[i][j], edges[i][k] + edges[k][j]);
            }
        }
    }
    edges
}

fn get_adjacents(x: usize, y: usize, w: usize, h: usize) -> Vec<(usize, usize)> {
    let mut adjacents = vec![];
    if x > 0 {
        adjacents.push((x - 1, y));
    }
    if y > 0 {
        adjacents.push((x, y - 1));
    }
    adjacents.push((x, y));
    if y < h - 1 {
        adjacents.push((x, y + 1));
    }
    if x < w - 1 {
        adjacents.push((x + 1, y));
    }
    adjacents
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}
