class Solution {
public int solution(int X, int[] A) {
// write your code in Java SE 8
int numberOfPositions = 0;
int result = -1;
int[] array = new int[X];
int index = 0;
// Initialize array
for (int i : array) {
array[index] = -1;
index++;
}
index = 0;
for (int i : A) {
try {
if (array[i - 1] == -1) {
array[i - 1] = index;
numberOfPositions++;
if (index > result)
result = index;
if (X == numberOfPositions) {
break;
}
index++;
} else {
index++;
continue;
}
} catch (Exception e) {
index++;
continue;
}
}
if (X == numberOfPositions)
// System.out.println(result);
return result;
else
// System.out.println("-1”);
return -1;
}
}