Problem:
Score : 100 points

Problem Statement

We have five variables x_1, x_2, x_3, x_4, and x_5.

The variable x_i was initially assigned a value of i.

Snuke chose one of these variables and assigned it 0.

You are given the values of the five variables after this assignment.

Find out which variable Snuke assigned 0.

Constraints

The values of x_1, x_2, x_3, x_4, and x_5 given as input are a possible outcome of the assignment by Snuke.

Input

Input is given from Standard Input in the following format:

x_1 x_2 x_3 x_4 x_5

Output

If the variable Snuke assigned 0 was x_i, print the integer i.

Sample Input 1

0 2 3 4 5

Sample Output 1

1

In this case, Snuke assigned 0 to x_1, so we should print 1.

Sample Input 2

1 2 0 4 5

Sample Output 2

3

Solution in Java (OpenJDK 11.0.6) (judge verdict: Wrong Answer)

import java.util.*;

class Main
{
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        int x = input.nextInt();
        int n = input.nextInt();
        ArrayList<Integer> p = new ArrayList();
        for (int i = 0; i < n; i++) {
            p.add(input.nextInt());
        }
        int left=x-1, right=x+1;

        Collections.sort(p);
        if(!p.contains(x)){
            System.out.print(x);
        }else{
            for(int i=0; i<n; i++){
                if(p.contains(left)){
                    left--;
                }
                if(p.contains(right)){
                    right++;
                }
                if(!p.contains(left)&&!p.contains(right)){
                    if(Math.abs(x-left)>Math.abs(x-right)){
                        System.out.print(right);
                        
                        return;
                    }else{
                        System.out.print(left);
                        return;
                    }
                }
            }
        }
    }
}