public int solution(int x, int[] array) {
		boolean[] leaf = new boolean[x + 1];
		long sumOfLeavesNeeded = sumOfAllPositiveNumbersUpTo(x);
		long currentSum = 0;

		for (int i = 0; i < array.length; i++) {
			int position = array[i];
			if (position > x || leaf[position]) {
				continue;
			}
			leaf[position] = true;
			currentSum += position;
			if (currentSum == sumOfLeavesNeeded) {
				return i;
			}
		}
		return -1;
	}