You are given a grid of squares with H horizontal rows and W vertical columns, where each square is painted white or black. HW characters from A_{11} to A_{HW} represent the colors of the squares. A_{ij} is `#` if the square at the i-th row from the top and the j-th column from the left is black, and A_{ij} is `.` if that square is white.  We will repeatedly perform the following operation until all the squares are black:    * Every white square that shares a side with a black square, becomes black.  Find the number of operations that will be performed. The initial grid has at least one black square.
def get_ij_black(W, rows):
  ans = None
  for i, row in enumerate(rows):
    for j, a in enumerate(row):
      if a == "#":
        cnt = max([i,j,W-1-i,H-1-j]) + 1
        print(cnt)
        if ans is None or ans > cnt:
          ans = cnt
  return ans


def get_closest_cross_dist(i,j,H,W,distlist):
  return 

H, W = map(int, input().split())
rows = [input() for i in range(H)]
ans = get_ij_black(W, rows)
print(ans)
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import numpy as np
# from time import perf_counter


def main():
    h, w = map(int, input().split())
    max_value = h + w
    gridmap = []

    for y in range(h):
        gridmap.append([0 if v == '#' else max_value for v in input().strip()])

    values = np.array(gridmap)

    for x in range(w - 1):
        values[:, x + 1] = np.minimum(values[:, x] + 1, values[:, x + 1])

    for x in range(w - 1, 0, -1):
        values[:, x - 1] = np.minimum(values[:, x] + 1, values[:, x - 1])

    for y in range(h - 1):
        values[y + 1, :] = np.minimum(values[y, :] + 1, values[y + 1, :])

    for y in range(h - 1, 0, -1):
        values[y - 1, :] = np.minimum(values[y, :] + 1, values[y - 1, :])

    print(np.max(values))


if __name__ == '__main__':
    # st = perf_counter()
    main()
    # ed = perf_counter()
    # print(ed - st)
