

#include <stdlib.h>
#include <stdio.h>
#include <iostream>
#include <string.h>
#include <string>
#include <vector>
#include <list>
using namespace std;
#include <stdio.h>
#include <map> 
#include <algorithm>
#include <functional>
#include <algorithm>
#include <functional>
#include <array>
#include <iostream>
#include <limits>
#include <numeric>
#include <type_traits>


int  H, W;
std::vector<int> len;

int maze[20][20] = {};
struct pos {
	int x = 0;
	int y = 0;
};

std::vector<pos> tail[400];

int mazelen[20][20] = {};

bool update(pos pp) {

	pos p = pp;
	pos offset[] = {
		0, 1,
		0, -1,
		1, 0,
		-1, 0,
	};

	for (int i = 0; i < 4; ++i) {
		offset[i].x += p.x;
		offset[i].y += p.y;

		offset[i].x = std::min(W-1, offset[i].x);
		offset[i].x = std::max(0, offset[i].x);

		offset[i].y = std::min(H-1, offset[i].y);
		offset[i].y = std::max(0, offset[i].y);
	}

	int n = mazelen[pp.x][pp.y];
	bool find = false;

	for (int i = 0; i < 4; ++i) {
		auto c = offset[i];
		if ((mazelen[c.x][c.y] == 0) && (maze[c.x][c.y] == 0)) {
			mazelen[c.x][c.y] = n + 1;

			tail[n + 1].push_back(c);
			find = true;
		}
	}
	return find;
}

int maze_len() {
	
	bool find = false;

	int currentLen = 0;
	for (int i = 0; i < tail[currentLen].size(); ++i) {
		const auto p = tail[currentLen][i];
	}



	return 0;
}

int main()
{
	std::string S;
	cin >> H >> W;

//	int maze[20][20] = {};

	for (int h = 0; h < H; ++h) {
		for (int w = 0; w < W; ++w) {
			char a;
			cin >> a;
			if (a == '.') {
				maze[w][h] = 0;
			} else {
				maze[w][h] = 1;
			}
		}
	}

	int mm = 0;


	for (int y = 0; y < H; ++y) {
		for (int x = 0; x < W; ++x) {
			if (maze[x][y]) {
				continue;
			}

			pos c;
			c.x = x; c.y = y;

			for (int i = 0; i < 400; ++i) {
				tail[i].clear();
			}
			std::memset(mazelen, 0, sizeof(mazelen));

			tail[1].push_back(c);
			mazelen[x][y] = 1;

			for (int i = 1; i < 400; ++i) {
				bool b = false;
				for (int j = 0; j < tail[i].size(); ++j) {
					b |= update(tail[i][j]);
				}
				if (b == false) {
					mm = std::max(i - 1, mm);
					break;
				}
			}
		}
	}


	printf("%d\n", mm);


	return 0;
}


