#include <iostream>
#include <cstdio>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <math.h>
#include <map>
#include <functional>
#include <iomanip>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <typeinfo>
#define PI 3.14159265359
#define INF 99999999
#define rep(i, n) for(int i=0; i<n; i++)
#define REP(n) rep(i, n)
#define EPS 1e-10
#define pb push_back
#define mp make_pair
typedef long long ll;
using namespace std;
typedef pair<int, int> P;

bool isLeap(int y);
ll gcd(ll a, ll b);
ll lcm(ll a, ll b);
double distanceAB(double xa, double ya, double xb, double yb);
void trace(int A[], int N);

/*
class Target
{
public:
	vector <string> draw(int n)
	{

	}
};
*/


int W, H;
queue<P> que;
char C[20][20];
int Ci[20][20];
int dx[] = {0, 1, 0, -1};
int dy[] = {-1, 0, 1, 0};

void dfs(int h, int w)
{
	C[h][w] = '*';
	que.push(P(h, w));
	Ci[h][w] = 0;
	rep(i, 4)
	{
		int nx = w + dx[i];
		int ny = h + dy[i];
		if (0 <= nx && nx < W && 0 <= ny && ny < H && C[ny][nx] == '.')
		{
			dfs(ny, nx);
		}
	}
}

int bfs()
{
	while (que.size())
	{
		P p = que.front(); que.pop();
		rep(i, 4)
		{
			int nx = p.second + dx[i];
			int ny = p.first + dy[i];
			if (C[ny][nx] == '.')
			{
				return Ci[p.first][p.second];
			}
			if (0 <= nx && nx < W && 0 <= ny && ny < H && C[ny][nx] == '#' && Ci[ny][nx] == INF)
			{
				que.push(P(ny, nx));
				Ci[ny][nx] = Ci[p.first][p.second] + 1;
			}
		}
	}
}


int main()
{
	cin >> W >> H;
	rep(i, H) rep(j, W) cin >> C[i][j];
	
	rep(i, H) rep(j, W) Ci[i][j] = INF;
	
	bool flag = false;
	rep(i, H)
	{
		rep(j, W)
		{
			if (C[i][j] == '.')
			{
				dfs(i, j);
				flag = true;
				break;
			}
		}
		if (flag) break;
	}
	
	int ans = bfs();
	
	cout << ans << endl;
	
	/*
	rep(i, H)
	{
		rep(j, W)
		{
			cout << C[i][j];
		}
		cout << endl;
	}
	*/
	
	return 0;
}


bool isLeap(int y)
{
	return y % 400 == 0
						? true : y % 100 == 0
						? false : y % 4 == 0
						? true : false;
}

ll gcd(ll a, ll b)
{
	return (b > 0) ? gcd(b, a % b) : a;
}

ll lcm(ll a, ll b)
{
	return a / gcd(a, b) * b;
}

void trace(int A[], int N)
{
	REP(N)
	{
		if (i > 0) cout << " ";
		cout << A[i];
	}
	cout << endl;
}

double distanceAB(double xa, double ya, double xb, double yb)
{
	return sqrt((xb-xa)*(xb-xa) + (yb-ya)*(yb-ya));
}