import java.util.ArrayList;
public class PuppetDraw {
public static void main(String[] args) {
int [][] board = {{0,0,0,0,0},{0,0,1,0,3},{0,2,5,0,1},{4,2,4,4,2},{3,5,1,3,1}};
int [] moves = {1,5,3,5,1,2,1,4};
int answer = 0;
int gameBoard[][] = board;
ArrayList<Integer> bucket = new ArrayList<>();
for(int i=0; i<moves.length; i++){
for(int j=0; j<gameBoard.length; j++){
int puppet = gameBoard[j][moves[i]-1];
if(puppet > 0){
bucket.add(puppet);
gameBoard[j][moves[i]-1] = 0;
break;
}
}
}
int current_size = bucket.size();
for( int i=0; i<bucket.size()-1; i++){
if(bucket.get(i).equals(bucket.get(i+1))){
bucket.remove(i);
bucket.remove(i);
i=-1;
}
}
System.out.println(current_size-bucket.size());
}
}