Untitled

mail@pastecode.io avatar
unknown
plain_text
2 months ago
751 B
0
Indexable
Never
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        
        int k = scanner.nextInt();
        scanner.nextLine(); // Consume newline
        
        String[] sequence = scanner.nextLine().split(" ");
        
        int count = 0;
        int result = -1;
        
        for (String num : sequence) {
            int n = Integer.parseInt(num);
            if (n == -1) break; // Stop when encountering -1
            if (n % 2 != 0) {
                count++;
                if (count == k) {
                    result = n;
                    break;
                }
            }
        }
        
        System.out.println(result);
    }
}
Leave a Comment