import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;

public class Main {
    char[][] board = new char[1000][];
    int H,W;
    List<Integer> sharpx = new ArrayList<>();
    List<Integer> sharpy = new ArrayList<>();
    List<Integer> tmpSharpx = new ArrayList<>();
    List<Integer> tmpSharpy = new ArrayList<>();
    int countSharp;
    private static Scanner sc;
    public static void main(String[] args) {
        Main instance = new Main();
        sc = instance.new Scanner();
        instance.solve();
    }

    private void solve() {
        try {
            H = sc.nextInt();
            W = sc.nextInt();
            countSharp = 0;

            for (int i = 0; i < H; i++) {
                board[i] = new char[1001];
                String input = sc.next();
                for (int j = 0; j < W; j++) {
                    board[i][j] = input.charAt(j);
                    if (board[i][j] == '#') {
                        sharpx.add(j);
                        sharpy.add(i);
                        countSharp++;
                    }
                }
            }

            int count = 0;

            while (countSharp < H * W) {
                tmpSharpx.clear();
                tmpSharpy.clear();
                for (int i = 0; i < sharpx.size(); i++) {
                    int sx = sharpx.get(i);
                    int sy = sharpy.get(i);
                    color(sx, sy);
                }
                sharpx.clear();
                sharpy.clear();
                sharpx.addAll(tmpSharpx);
                sharpy.addAll(tmpSharpy);
                count ++;
            }

            System.out.println(count);


        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private void color (int x, int y) {
        if (x == 0) {
            if (board[y][x+1] == '.') {
                board[y][x + 1] = '#';
                tmpSharpx.add(x + 1);
                tmpSharpy.add(y);
                countSharp++;
            }
        } else if (x == W - 1) {
            if (board[y][x-1] == '.') {
                board[y][x - 1] = '#';
                tmpSharpx.add(x - 1);
                tmpSharpy.add(y);
                countSharp++;
            }
        } else {
            if (board[y][x+1] == '.') {
                board[y][x + 1] = '#';
                tmpSharpx.add(x + 1);
                tmpSharpy.add(y);
                countSharp++;
            }
            if (board[y][x-1] == '.') {
                board[y][x - 1] = '#';
                tmpSharpx.add(x - 1);
                tmpSharpy.add(y);
                countSharp++;
            }
        }

        if (y == 0) {
            if (board[y+1][x] == '.') {
                board[y + 1][x] = '#';
                tmpSharpx.add(x);
                tmpSharpy.add(y + 1);
                countSharp++;
            }
        } else if (y == H - 1) {
            if (board[y-1][x] == '.') {
                board[y-1][x] = '#';
                tmpSharpx.add(x);
                tmpSharpy.add(y-1);
                countSharp++;
            }
        } else {
            if (board[y+1][x] == '.') {
                board[y + 1][x] = '#';
                tmpSharpx.add(x);
                tmpSharpy.add(y + 1);
                countSharp++;
            }
            if (board[y-1][x] == '.') {
                board[y-1][x] = '#';
                tmpSharpx.add(x);
                tmpSharpy.add(y-1);
                countSharp++;
            }
        }
    }

    private class Scanner {
        String[] s;
        int i;
        BufferedReader br;
        String regex = " ";

        public Scanner() {
            s = new String[0];
            i = 0;
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        @Override
        protected void finalize() throws Throwable {
            try {
                super.finalize();
            } finally {
                destruction();
            }
        }

        private void destruction() throws IOException {
            if (br != null) br.close();
        }

        public String next() throws IOException {
            if (i < s.length) return s[i++];
            String st = br.readLine();
            while (st == "") st = br.readLine();
            s = st.split(regex, 0);
            i = 0;
            return s[i++];
        }

        public int nextInt() throws NumberFormatException, IOException {
            return Integer.parseInt(next());
        }

        public Long nextLong() throws NumberFormatException, IOException {
            return Long.parseLong(next());
        }

        public Double nextDouble() throws NumberFormatException, IOException {
            return Double.parseDouble(next());
        }
    }
}

Measured memory_bytes: 112564