Create an auxiliary array of next row with the element and it 's position
ArrayList < int [ ] > aux = new ArrayList < > ( ) ; for ( int j = 0 ; j < m ; ++ j ) { aux . add ( new int [ ] { V [ i + 1 ] [ j ] , j } ) ; }