Zero One Matrix

medium
Given an m*n binary matrix mat, return the distance of the nearest 0 for each cell.

The distance between two adjacent cells is 1.

Input Format

First line contains two integers n and m. Each of next n lines contain m numbers containing either 0 or 1.

Output Format

print a 2d matrix where each box contains distance to its nearest 0.

Constraints

1<= n <= 1000
1<= e <= n*(n-1)/2

Example

Input
3 3
0 0 0
0 1 1
1 1 1
Output
0 0 0 
0 1 1 
1 2 2 
Previous
Number Of Enclaves
Next
Number Of Distinct Island

Related Questions