import java.util.*;

public class Main {
    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int[] arr = new int[n];

        for(int i = 0; i < n; i++) {
            arr[i] = sc.nextInt();
        }

        int L = sc.nextInt();
        int R = sc.nextInt();

        int required = R - L + 1;

        Map<Integer,Integer> freq = new HashMap<>();

        int distinct = 0;
        int left = 0;
        int ans = Integer.MAX_VALUE;

        // arr = 1 2 2 3 2 4 5 5 3 4 6 and l = 3, r = 5 i need to catch 5, 3, 4
        // i have to be able to move on from local min(3,2,4,5), i also need to make sure only the elements 
        // i care about are in window, if i find a good satisfying window, 
        // i still need to move on from it n explore others
        for(int right = 0; right < n; right++) {
            if(arr[right] >= L && arr[right] <= R) {
                freq.put(arr[right], freq.getOrDefault(arr[right], 0) + 1);
                if(freq.get(arr[right]) == 1) {
                    distinct++;
                }
            }
            //we want to maintain the window in hashmap, i only insert the elem from l to r and if the size of hashmap
            // is l-r+1 then we found a window where all l  to r present, now just count the length of window 
            // and start to remove the elem that r in window >l and <r so we can find some new window within the window
            // if we find a new window within window then its smaller and will be counted coz of while condition 
            // since distinct still = required
            while(distinct == required){
                ans = Math.min(ans, right-left+1);
                if(arr[left] >= L && arr[left] <= R) {
                    freq.put(arr[left], freq.get(arr[left]) - 1);
                    if(freq.get(arr[left]) == 0) {
                        freq.remove(arr[left]);
                        distinct--;
                    }
                }
                left++; // inc window to explore new
            }
        }
        System.out.println(ans);
    }
}