Function to print the grid , if possible
function printGrid ( grid , N , M ) { for ( let i = 0 ; i < N ; i ++ ) { for ( let j = 0 ; j < M ; j ++ ) { document . write ( grid [ i ] [ j ] + " " ) ; } document . write ( " " ) ; } }