Language: Java

Scanner console = new Scanner(System.in);
		int n = console.nextInt();		//number of boxes
		int m = console.nextInt();		//number of operations
		console.nextLine();
		
		int[][] boxInfo = new int[n][2];	//of 2, first is total count, second is 0 if no red, 1 if possible
		//boxInfo[n][0] gives total balls
		//boxInfo[n][1] gives possibility of red
		
		//intialize boxes
		for(int i = 0; i < n; i++) {
			if(i == 0)
				boxInfo[0][1] = 1;
			else
				boxInfo[i][1] = 0;
			boxInfo[i][0] = 1;
		}
		
		for(int i = 0; i < m; i++) {
			int box1 = console.nextInt() - 1;	//to adjust for zero indexing
			int box2 = console.nextInt() - 1;
			console.nextLine();
			
			//if could have red ball
			if(boxInfo[box1][1] == 1) {
				//if only one ball in box, and ball is taken out, no longer possible
				if(boxInfo[box1][0] == 1) {
					boxInfo[box1][1] = 0;
				}
				boxInfo[box2][1] = 1;	//possible for box 2 to have red ball
				boxInfo[box2][0]++;		//box 2 gains a ball
				boxInfo[box1][0]--;		//box 1 loses a ball
			}
		}
		
		//loop thru and count how many 1's in pos 1 of the array in each box
		int numPossible = 0;
		for(int i = 0; i < n; i++) 
			if(boxInfo[i][1] == 1) //if possible
				numPossible++;
		
		System.out.println(numPossible);

Compiler output:
Main.java:1: error: unnamed classes are a preview feature and are disabled by default.
Scanner console = new Scanner(System.in);
^
  (use --enable-preview to enable unnamed classes)
Main.java:4: error: class, interface, enum, or record expected
		console.nextLine();
		^
Main.java:11: error: class, interface, enum, or record expected
		for(int i = 0; i < n; i++) {
		^
Main.java:11: error: class, interface, enum, or record expected
		for(int i = 0; i < n; i++) {
		               ^
Main.java:11: error: class, interface, enum, or record expected
		for(int i = 0; i < n; i++) {
		                      ^
Main.java:14: error: class, interface, enum, or record expected
			else
			^
Main.java:16: error: class, interface, enum, or record expected
			boxInfo[i][0] = 1;
			^
Main.java:17: error: class, interface, enum, or record expected
		}
		^
Main.java:19: error: class, interface, enum, or record expected
		for(int i = 0; i < m; i++) {
		               ^
Main.java:19: error: class, interface, enum, or record expected
		for(int i = 0; i < m; i++) {
		                      ^
Main.java:22: error: class, interface, enum, or record expected
			console.nextLine();
			^
Main.java:25: error: class, interface, enum, or record expected
			if(boxInfo[box1][1] == 1) {
			^
Main.java:29: error: class, interface, enum, or record expected
				}
				^
Main.java:31: error: class, interface, enum, or record expected
				boxInfo[box2][0]++;		//box 2 gains a ball
				^
Main.java:32: error: class, interface, enum, or record expected
				boxInfo[box1][0]--;		//box 1 loses a ball
				^
Main.java:33: error: class, interface, enum, or record expected
			}
			^
Main.java:38: error: class, interface, enum, or record expected
		for(int i = 0; i < n; i++) 
		^
Main.java:38: error: class, interface, enum, or record expected
		for(int i = 0; i < n; i++) 
		               ^
Main.java:38: error: class, interface, enum, or record expected
		for(int i = 0; i < n; i++) 
		                      ^
Main.java:42: error: class, interface, enum, or record expected
		System.out.println(numPossible);
		^
20 errors