import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class F implements Runnable{

    static StringTokenizer st;
    static BufferedReader in;
    static PrintWriter pw;
    public static void solve() throws IOException{
        in = new BufferedReader(new FileReader("input.txt"));
        pw = new PrintWriter(new BufferedWriter(new FileWriter("output.txt")));
        int n = nextInt();
        int a = nextInt();
        int b = nextInt();
        int[]h = new int[n+1];
        int sum = 0;
        for (int i = 1; i <= n; i++) {
            h[i] = nextInt();
            sum += h[i];
        }
        if (a >= sum || b >= sum) {
            pw.println(0);
            pw.close();
            return;
        }
        int INF = (int) 1e9;
        int[][][]dp = new int[a+1][n+1][2];
        for (int i = 0; i <= a; i++) {
            for (int j = 0; j <= n; j++) {
                dp[i][j][0] = dp[i][j][1] = INF;
            }
        }
        for (int i = 0; i <= n; i++) {
            dp[0][i][0] = 0;
        }
        for (int i = 1; i <= a; i++) {
            for (int j = 1; j <= n; j++) {
                dp[i][j][0] = Math.min(dp[i][j-1][0], dp[i][j-1][1]+Math.min(h[j], h[j-1]));
                if (h[j] <= i) {
                    dp[i][j][1] = Math.min(dp[i-h[j]][j-1][1], dp[i-h[j]][j-1][0]+Math.min(h[j], h[j-1]));
                }
            }
        }
        int min = INF;
        for (int i = 0; i <= a; i++) {
            if (b >= sum-i) {
                min = Math.min(min, Math.min(dp[i][n][0], dp[i][n][1]));
            }
        }
        if (min==INF)
            pw.println(-1);
        else
            pw.println(min);
        pw.close();
    }
    private static int nextInt() throws IOException{
        return Integer.parseInt(next());
    }

    private static String next() throws IOException {
        while (st == null || !st.hasMoreTokens()) {
            st = new StringTokenizer(in.readLine());
        }
        return st.nextToken();
    }

    static Throwable uncaught;
    static FastScanner sc;
    @Override
    public void run() {
        try {
            //in = new BufferedReader(new InputStreamReader(System.in));
            //out = new PrintWriter(System.out);
            in = new BufferedReader(new FileReader("input.txt"));
            pw = new PrintWriter(new FileWriter("output.txt"));
            sc = new FastScanner(in);
            solve();
        } catch (Throwable t) {
            F.uncaught = t;
        } finally {
            pw.close();
        }
    }

    public static void main(String[] args) throws Throwable {
        Thread t = new Thread(null, new F(), "", 128 * 1024 * 1024);
        t.start();
        t.join();
        if (uncaught != null) {
            throw uncaught;
        }
    }
}
class FastScanner {

    BufferedReader reader;
    StringTokenizer strTok;

    public FastScanner(BufferedReader reader) {
        this.reader = reader;
    }

    public String nextToken() throws IOException {
        while (strTok == null || !strTok.hasMoreTokens()) {
            strTok = new StringTokenizer(reader.readLine());
        }
        return strTok.nextToken();
    }

    public int nextInt() throws IOException {
        return Integer.parseInt(nextToken());
    }

    public long nextLong() throws IOException {
        return Long.parseLong(nextToken());
    }

    public double nextDouble() throws IOException {
        return Double.parseDouble(nextToken());
    }

}


import java.io.BufferedReader;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class F implements Runnable{

    static StringTokenizer st;
    static BufferedReader in;
    static PrintWriter pw;
    void solve() throws IOException{
        int n = sc.nextInt();
        int a = sc.nextInt();
        int b = sc.nextInt();
        int[]h = new int[n+1];
        int sum = 0;
        for (int i = 1; i <= n; i++) {
            h[i] = sc.nextInt();
            sum += h[i];
        }
        if (a >= sum || b >= sum) {
            pw.println(0);
            pw.close();
            return;
        }
        int INF = (int) 1e9;
        int[][][]dp = new int[a+1][n+1][2];
        for (int i = 0; i <= a; i++) {
            for (int j = 0; j <= n; j++) {
                dp[i][j][0] = dp[i][j][1] = INF;
            }
        }
        for (int i = 0; i <= n; i++) {
            dp[0][i][0] = 0;
        }
        for (int i = 1; i <= a; i++) {
            for (int j = 1; j <= n; j++) {
                dp[i][j][0] = Math.min(dp[i][j-1][0], dp[i][j-1][1]+Math.min(h[j], h[j-1]));
                if (h[j] <= i) {
                    dp[i][j][1] = Math.min(dp[i-h[j]][j-1][1], dp[i-h[j]][j-1][0]+Math.min(h[j], h[j-1]));
                }
            }
        }
        int min = INF;
        for (int i = 0; i <= a; i++) {
            if (b >= sum-i) {
                min = Math.min(min, Math.min(dp[i][n][0], dp[i][n][1]));
            }
        }
        if (min==INF)
            pw.println(-1);
        else
            pw.println(min);
        pw.close();
    }

    static Throwable uncaught;
    static FastScanner sc;
    @Override
    public void run() {
        try {
            //in = new BufferedReader(new InputStreamReader(System.in));
            //out = new PrintWriter(System.out);
            in = new BufferedReader(new FileReader("input.txt"));
            pw = new PrintWriter(new FileWriter("output.txt"));
            sc = new FastScanner(in);
            solve();
        } catch (Throwable t) {
            F.uncaught = t;
        } finally {
            pw.close();
        }
    }

    public static void main(String[] args) throws Throwable {
        Thread t = new Thread(null, new F(), "", 128 * 1024 * 1024);
        t.start();
        t.join();
        if (uncaught != null) {
            throw uncaught;
        }
    }
}
class FastScanner {

    BufferedReader reader;
    StringTokenizer strTok;

    public FastScanner(BufferedReader reader) {
        this.reader = reader;
    }

    public String nextToken() throws IOException {
        while (strTok == null || !strTok.hasMoreTokens()) {
            strTok = new StringTokenizer(reader.readLine());
        }
        return strTok.nextToken();
    }

    public int nextInt() throws IOException {
        return Integer.parseInt(nextToken());
    }

    public long nextLong() throws IOException {
        return Long.parseLong(nextToken());
    }

    public double nextDouble() throws IOException {
        return Double.parseDouble(nextToken());
    }

}


import java.io.* ;
import java.util.*;

import static java.lang.Math.* ;
import static java.util.Arrays.* ;

public class B {

	public static void main(String[] args) throws IOException {

		in.setInTXT();
		outh.setOutTXT();

		new B().solveProblem();

		outh.out.close();
	}

	static Input in = new Input() ;
	static PrintStream out = new PrintStream(new BufferedOutputStream(System.out));
	static Output outh = new Output(out) ;

	int n, a, b;
	int[] h ;

	public void solveProblem() throws IOException {

		n = in.nextInt();
		a = in.nextInt();
		b = in.nextInt();

		if( a < b ){
			int t = b ;
			b = a;
			a = t;
		}
		h = in.nextInt(n);

		int[] dpa = new int[a+1];
		int[] dpb = new int[a+1];
		fill( dpa, Integer.MAX_VALUE);
		fill( dpb, Integer.MAX_VALUE);
		int som = h[0];

		dpa[h[0]] = 0;
		dpb[0] = 0;

		for( int i = 1; i < n ;i ++){

			int[] nua = new int[a+1];
			int[] nub = new int[a+1];
			fill( nua, Integer.MAX_VALUE);
			fill( nub, Integer.MAX_VALUE);

			for( int j = 0 ; j <= a; j++){
				int na = j;
				int nb = som - j;

				if( nb + h[i] <= b ){
					if( dpa[na] < Integer.MAX_VALUE)
						nub[na] = min(nub[na],dpa[na]+min(h[i],h[i-1]));
					nub[na] = min(nub[na],dpb[na]);
				}

				if( na + h[i] <= a){
					int no = na;
					na += h[i];
					nua[na] = min(nua[na],dpa[no]);
					if( dpb[no] < Integer.MAX_VALUE)
						nua[na] = min(nua[na],dpb[no]+min(h[i],h[i-1]));
				}
			}

			dpa = nua;
			dpb = nub;

			som += h[i];

		}

		int min = Integer.MAX_VALUE;
		for( int i : dpa)
			min = min(min,i);
		for( int i : dpb)
			min = min(min,i);
		out.println(min == Integer.MAX_VALUE ? -1 : min);
	}

	static void p( Object ...p){
		System.out.println(Arrays.deepToString(p));
	}

	static class Input {

		BufferedReader buf = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer tokens ;

		public int nextInt(){
			return Integer.parseInt(next()) ;
		}

		public int[] nextInt(int n ){
			int[] res = new int[n] ;
			for( int i = 0 ; i < n ; i++ )
				res[i] = nextInt() ;
			return res ;
		}

		public long nextLong(){
			return Long.parseLong(next()) ;
		}

		public long[] nextLong(int n ){
			long[] res = new long[n] ;
			for( int i = 0 ; i < n ; i++ )
				res[i] = nextLong() ;
			return res ;
		}

		public double nextDouble(){
			return Double.parseDouble(next()) ;
		}

		public String next(){

			try{
				while( tokens == null || !tokens.hasMoreTokens() )
					tokens = new StringTokenizer(buf.readLine()) ;
			}catch( Exception e ){
				e.printStackTrace() ;
			}

			return tokens.nextToken() ;
		}

		public void setInTXT(){
			try {
				buf = new BufferedReader(new InputStreamReader(new FileInputStream("input.txt")));
			} catch (FileNotFoundException e) {
				e.printStackTrace();
			}
		}
	}

	static class Output {

		PrintStream out ;

		public Output(PrintStream out) {
			this.out = out;
		}

		void print(String s){
			out.print(s);
		}

		void println(String s){
			out.println(s);
		}

		void wr( int[] rij ){
			for( int i = 0 ; i < rij.length - 1 ; i++ )
				out.print(rij[i] + " ") ;
			out.println(rij[rij.length-1]);
		}

		void wr( long[] rij ){
			for( int i = 0 ; i < rij.length - 1 ; i++ )
				out.print(rij[i] + " ") ;
			out.println(rij[rij.length-1]);
		}

		void wr( char[] rij){
			out.println(new String(rij)) ;
		}

		void setOutTXT() {
			try {
				out = new PrintStream(new BufferedOutputStream(new FileOutputStream("output.txt")));
			} catch (FileNotFoundException e) {
				e.printStackTrace();
			}
		}

	}
}


import java.io.* ;
import java.util.*;

import static java.lang.Math.* ;
import static java.util.Arrays.* ;

public class B {

	public static void main(String[] args) throws IOException {

		in.setInTXT();
		outh.setOutTXT();

		new B().solveProblem();

		outh.out.close();
	}

	static Input in = new Input() ;
	static PrintStream out = new PrintStream(new BufferedOutputStream(System.out));
	static Output outh = new Output(out) ;

	int n, a, b;
	int[] h ;

	public void solveProblem() throws IOException {

		n = in.nextInt();
		a = in.nextInt();
		b = in.nextInt();

		if( a < b ){
			int t = b ;
			b = a;
			a = t;
		}
		h = in.nextInt(n);

		int[] dpa = new int[a+1];
		int[] dpb = new int[a+1];
		fill( dpa, Integer.MAX_VALUE);
		fill( dpb, Integer.MAX_VALUE);
		int som = h[0];

		dpa[h[0]] = 0;
		dpb[0] = 0;

		for( int i = 1; i < n ;i ++){

			int[] nua = new int[a+1];
			int[] nub = new int[a+1];
			fill( nua, Integer.MAX_VALUE);
			fill( nub, Integer.MAX_VALUE);

			for( int j = 0 ; j <= a; j++){
				int na = j;
				int nb = som - j;

				if( nb + h[i] <= b ){
					if( dpa[na] < Integer.MAX_VALUE)
						nub[na] = min(nub[na],dpa[na]+min(h[i],h[i-1]));
					nub[na] = min(nub[na],dpb[na]);
				}

				if( na + h[i] <= a){
					int no = na;
					na += h[i];
					nua[na] = min(nua[na],dpa[no]);
					if( dpb[no] < Integer.MAX_VALUE)
						nua[na] = min(nua[na],dpb[no]+min(h[i],h[i-1]));
				}
			}

			dpa = nua;
			dpb = nub;

			som += h[i];

		}

		int min = Integer.MAX_VALUE;
		for( int i : dpa)
			min = min(min,i);
		for( int i : dpb)
			min = min(min,i);
		outh.out.println(min == Integer.MAX_VALUE ? -1 : min);
	}

	static void p( Object ...p){
		System.out.println(Arrays.deepToString(p));
	}

	static class Input {

		BufferedReader buf = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer tokens ;

		public int nextInt(){
			return Integer.parseInt(next()) ;
		}

		public int[] nextInt(int n ){
			int[] res = new int[n] ;
			for( int i = 0 ; i < n ; i++ )
				res[i] = nextInt() ;
			return res ;
		}

		public long nextLong(){
			return Long.parseLong(next()) ;
		}

		public long[] nextLong(int n ){
			long[] res = new long[n] ;
			for( int i = 0 ; i < n ; i++ )
				res[i] = nextLong() ;
			return res ;
		}

		public double nextDouble(){
			return Double.parseDouble(next()) ;
		}

		public String next(){

			try{
				while( tokens == null || !tokens.hasMoreTokens() )
					tokens = new StringTokenizer(buf.readLine()) ;
			}catch( Exception e ){
				e.printStackTrace() ;
			}

			return tokens.nextToken() ;
		}

		public void setInTXT(){
			try {
				buf = new BufferedReader(new InputStreamReader(new FileInputStream("input.txt")));
			} catch (FileNotFoundException e) {
				e.printStackTrace();
			}
		}
	}

	static class Output {

		PrintStream out ;

		public Output(PrintStream out) {
			this.out = out;
		}

		void print(String s){
			out.print(s);
		}

		void println(String s){
			out.println(s);
		}

		void wr( int[] rij ){
			for( int i = 0 ; i < rij.length - 1 ; i++ )
				out.print(rij[i] + " ") ;
			out.println(rij[rij.length-1]);
		}

		void wr( long[] rij ){
			for( int i = 0 ; i < rij.length - 1 ; i++ )
				out.print(rij[i] + " ") ;
			out.println(rij[rij.length-1]);
		}

		void wr( char[] rij){
			out.println(new String(rij)) ;
		}

		void setOutTXT() {
			try {
				out = new PrintStream(new BufferedOutputStream(new FileOutputStream("output.txt")));
			} catch (FileNotFoundException e) {
				e.printStackTrace();
			}
		}

	}
}


import java.io.* ;
import java.util.*;

import static java.lang.Math.* ;
import static java.util.Arrays.* ;

public class B {

	public static void main(String[] args) throws IOException {

//		in.setInTXT();
//		outh.setOutTXT();

		new B().solveProblem();

		outh.out.close();
	}

	static Input in = new Input() ;
	static PrintStream out = new PrintStream(new BufferedOutputStream(System.out));
	static Output outh = new Output(out) ;

	int n, a, b;
	int[] h ;

	public void solveProblem() throws IOException {

		n = in.nextInt();
		a = in.nextInt();
		b = in.nextInt();

		if( a < b ){
			int t = b ;
			b = a;
			a = t;
		}
		h = in.nextInt(n);

		int[] dpa = new int[a+1];
		int[] dpb = new int[a+1];
		fill( dpa, Integer.MAX_VALUE);
		fill( dpb, Integer.MAX_VALUE);
		int som = h[0];

		dpa[h[0]] = 0;
		dpb[0] = 0;

		for( int i = 1; i < n ;i ++){

			int[] nua = new int[a+1];
			int[] nub = new int[a+1];
			fill( nua, Integer.MAX_VALUE);
			fill( nub, Integer.MAX_VALUE);

			for( int j = 0 ; j <= a; j++){
				int na = j;
				int nb = som - j;

				if( nb + h[i] <= b ){
					if( dpa[na] < Integer.MAX_VALUE)
						nub[na] = min(nub[na],dpa[na]+min(h[i],h[i-1]));
					nub[na] = min(nub[na],dpb[na]);
				}

				if( na + h[i] <= a){
					int no = na;
					na += h[i];
					nua[na] = min(nua[na],dpa[no]);
					if( dpb[no] < Integer.MAX_VALUE)
						nua[na] = min(nua[na],dpb[no]+min(h[i],h[i-1]));
				}
			}

			dpa = nua;
			dpb = nub;

			som += h[i];

		}

		int min = Integer.MAX_VALUE;
		for( int i : dpa)
			min = min(min,i);
		for( int i : dpb)
			min = min(min,i);
		out.println(min == Integer.MAX_VALUE ? -1 : min);
	}

	static void p( Object ...p){
		System.out.println(Arrays.deepToString(p));
	}

	static class Input {

		BufferedReader buf = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer tokens ;

		public int nextInt(){
			return Integer.parseInt(next()) ;
		}

		public int[] nextInt(int n ){
			int[] res = new int[n] ;
			for( int i = 0 ; i < n ; i++ )
				res[i] = nextInt() ;
			return res ;
		}

		public long nextLong(){
			return Long.parseLong(next()) ;
		}

		public long[] nextLong(int n ){
			long[] res = new long[n] ;
			for( int i = 0 ; i < n ; i++ )
				res[i] = nextLong() ;
			return res ;
		}

		public double nextDouble(){
			return Double.parseDouble(next()) ;
		}

		public String next(){

			try{
				while( tokens == null || !tokens.hasMoreTokens() )
					tokens = new StringTokenizer(buf.readLine()) ;
			}catch( Exception e ){
				e.printStackTrace() ;
			}

			return tokens.nextToken() ;
		}

		public void setInTXT(){
			try {
				buf = new BufferedReader(new InputStreamReader(new FileInputStream("input.txt")));
			} catch (FileNotFoundException e) {
				e.printStackTrace();
			}
		}
	}

	static class Output {

		PrintStream out ;

		public Output(PrintStream out) {
			this.out = out;
		}

		void print(String s){
			out.print(s);
		}

		void println(String s){
			out.println(s);
		}

		void wr( int[] rij ){
			for( int i = 0 ; i < rij.length - 1 ; i++ )
				out.print(rij[i] + " ") ;
			out.println(rij[rij.length-1]);
		}

		void wr( long[] rij ){
			for( int i = 0 ; i < rij.length - 1 ; i++ )
				out.print(rij[i] + " ") ;
			out.println(rij[rij.length-1]);
		}

		void wr( char[] rij){
			out.println(new String(rij)) ;
		}

		void setOutTXT() {
			try {
				out = new PrintStream(new BufferedOutputStream(new FileOutputStream("output.txt")));
			} catch (FileNotFoundException e) {
				e.printStackTrace();
			}
		}

	}
}


import java.io.* ;
import java.util.*;

import static java.lang.Math.* ;
import static java.util.Arrays.* ;

public class B {

	public static void main(String[] args) throws IOException {

		in.setInTXT();
		outh.setOutTXT();

		new B().solveProblem();

		outh.out.close();
	}

	static Input in = new Input() ;
	static PrintStream out = new PrintStream(new BufferedOutputStream(System.out));
	static Output outh = new Output(out) ;

	int n, a, b;
	int[] h ;

	public void solveProblem() throws IOException {

		n = in.nextInt();
		a = in.nextInt();
		b = in.nextInt();

		if( a < b ){
			int t = b ;
			b = a;
			a = t;
		}
		h = in.nextInt(n);

		int[] dpa = new int[a+1];
		int[] dpb = new int[a+1];
		fill( dpa, Integer.MAX_VALUE);
		fill( dpb, Integer.MAX_VALUE);
		int som = h[0];

		if( h[0] <= a)
			dpa[h[0]] = 0;

		if( h[0] <= b)
			dpb[0] = 0;

		for( int i = 1; i < n ;i ++){

			int[] nua = new int[a+1];
			int[] nub = new int[a+1];
			fill( nua, Integer.MAX_VALUE);
			fill( nub, Integer.MAX_VALUE);

			for( int j = 0 ; j <= a; j++){
				int na = j;
				int nb = som - j;

				if( nb + h[i] <= b ){
					if( dpa[na] < Integer.MAX_VALUE)
						nub[na] = min(nub[na],dpa[na]+min(h[i],h[i-1]));
					nub[na] = min(nub[na],dpb[na]);
				}

				if( na + h[i] <= a){
					int no = na;
					na += h[i];
					nua[na] = min(nua[na],dpa[no]);
					if( dpb[no] < Integer.MAX_VALUE)
						nua[na] = min(nua[na],dpb[no]+min(h[i],h[i-1]));
				}
			}

			dpa = nua;
			dpb = nub;

			som += h[i];

		}

		int min = Integer.MAX_VALUE;
		for( int i : dpa)
			min = min(min,i);
		for( int i : dpb)
			min = min(min,i);
		outh.out.println(min == Integer.MAX_VALUE ? -1 : min);
	}

	static void p( Object ...p){
		System.out.println(Arrays.deepToString(p));
	}

	static class Input {

		BufferedReader buf = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer tokens ;

		public int nextInt(){
			return Integer.parseInt(next()) ;
		}

		public int[] nextInt(int n ){
			int[] res = new int[n] ;
			for( int i = 0 ; i < n ; i++ )
				res[i] = nextInt() ;
			return res ;
		}

		public long nextLong(){
			return Long.parseLong(next()) ;
		}

		public long[] nextLong(int n ){
			long[] res = new long[n] ;
			for( int i = 0 ; i < n ; i++ )
				res[i] = nextLong() ;
			return res ;
		}

		public double nextDouble(){
			return Double.parseDouble(next()) ;
		}

		public String next(){

			try{
				while( tokens == null || !tokens.hasMoreTokens() )
					tokens = new StringTokenizer(buf.readLine()) ;
			}catch( Exception e ){
				e.printStackTrace() ;
			}

			return tokens.nextToken() ;
		}

		public void setInTXT(){
			try {
				buf = new BufferedReader(new InputStreamReader(new FileInputStream("input.txt")));
			} catch (FileNotFoundException e) {
				e.printStackTrace();
			}
		}
	}

	static class Output {

		PrintStream out ;

		public Output(PrintStream out) {
			this.out = out;
		}

		void print(String s){
			out.print(s);
		}

		void println(String s){
			out.println(s);
		}

		void wr( int[] rij ){
			for( int i = 0 ; i < rij.length - 1 ; i++ )
				out.print(rij[i] + " ") ;
			out.println(rij[rij.length-1]);
		}

		void wr( long[] rij ){
			for( int i = 0 ; i < rij.length - 1 ; i++ )
				out.print(rij[i] + " ") ;
			out.println(rij[rij.length-1]);
		}

		void wr( char[] rij){
			out.println(new String(rij)) ;
		}

		void setOutTXT() {
			try {
				out = new PrintStream(new BufferedOutputStream(new FileOutputStream("output.txt")));
			} catch (FileNotFoundException e) {
				e.printStackTrace();
			}
		}

	}
}


import java.io.OutputStreamWriter;
import java.io.BufferedWriter;
import java.util.Comparator;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.Writer;
import java.io.IOException;
import java.util.Arrays;
import java.util.InputMismatchException;
import java.io.FileOutputStream;
import java.io.FileInputStream;
import java.math.BigInteger;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 * @author Egor Kulikov (egor@egork.net)
 */
public class Main {
	public static void main(String[] args) {
		InputStream inputStream;
		try {
			inputStream = new FileInputStream("input.txt");
		} catch (IOException e) {
			throw new RuntimeException(e);
		}
		OutputStream outputStream;
		try {
			outputStream = new FileOutputStream("output.txt");
		} catch (IOException e) {
			throw new RuntimeException(e);
		}
		InputReader in = new InputReader(inputStream);
		OutputWriter out = new OutputWriter(outputStream);
		TaskB solver = new TaskB();
		solver.solve(1, in, out);
		out.close();
	}
}

class TaskB {
	public void solve(int testNumber, InputReader in, OutputWriter out) {
		int count = in.readInt();
		int red = in.readInt();
		int green = in.readInt();
		int[] heights = IOUtils.readIntArray(in, count);
		int[][] minBadness = new int[2][red + 1];
		int[][] next = new int[2][red + 1];
		ArrayUtils.fill(minBadness, Integer.MAX_VALUE);
		minBadness[0][0] = minBadness[1][0] = 0;
		int total = 0;
		int last = 0;
		for (int i : heights) {
			ArrayUtils.fill(next, Integer.MAX_VALUE);
			int cost = Math.min(i, last);
			for (int j = red; j >= 0; j--) {
				if (minBadness[0][j] != Integer.MAX_VALUE) {
					if (j <= red - i)
						next[0][j + i] = Math.min(next[0][j + i], minBadness[0][j]);
					next[1][j] = Math.min(next[1][j], minBadness[0][j] + cost);
				}
				if (minBadness[1][j] != Integer.MAX_VALUE) {
					next[1][j] = Math.min(next[1][j], minBadness[1][j]);
					if (j <= red - i)
						next[0][j + i] = Math.min(next[0][j + i], minBadness[1][j] + cost);
				}
			}
			last = i;
			total += i;
			int[][] temp = minBadness;
			minBadness = next;
			next = temp;
		}
		int answer = Integer.MAX_VALUE;
		for (int i = Math.max(0, total - green); i <= red; i++)
			answer = Math.min(answer, Math.min(minBadness[0][i], minBadness[1][i]));
		if (answer == Integer.MAX_VALUE)
			answer = -1;
		out.printLine(answer);
	}
}

class InputReader {

	private InputStream stream;
	private byte[] buf = new byte[1024];
	private int curChar;
	private int numChars;
	private SpaceCharFilter filter;

	public InputReader(InputStream stream) {
		this.stream = stream;
	}

	public int read() {
		if (numChars == -1)
			throw new InputMismatchException();
		if (curChar >= numChars) {
			curChar = 0;
			try {
				numChars = stream.read(buf);
			} catch (IOException e) {
				throw new InputMismatchException();
			}
			if (numChars <= 0)
				return -1;
		}
		return buf[curChar++];
	}

	public int readInt() {
		int c = read();
		while (isSpaceChar(c))
			c = read();
		int sgn = 1;
		if (c == '-') {
			sgn = -1;
			c = read();
		}
		int res = 0;
		do {
			if (c < '0' || c > '9')
				throw new InputMismatchException();
			res *= 10;
			res += c - '0';
			c = read();
		} while (!isSpaceChar(c));
		return res * sgn;
	}

	public boolean isSpaceChar(int c) {
		if (filter != null)
			return filter.isSpaceChar(c);
		return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
	}

	public interface SpaceCharFilter {
		public boolean isSpaceChar(int ch);
	}
}

class OutputWriter {
	private final PrintWriter writer;

	public OutputWriter(OutputStream outputStream) {
		writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
	}

	public OutputWriter(Writer writer) {
		this.writer = new PrintWriter(writer);
	}

	public void print(Object...objects) {
		for (int i = 0; i < objects.length; i++) {
			if (i != 0)
				writer.print(' ');
			writer.print(objects[i]);
		}
	}

	public void printLine(Object...objects) {
		print(objects);
		writer.println();
	}

	public void close() {
		writer.close();
	}

	}

class IOUtils {

	public static int[] readIntArray(InputReader in, int size) {
		int[] array = new int[size];
		for (int i = 0; i < size; i++)
			array[i] = in.readInt();
		return array;
	}

	}

class ArrayUtils {

	public static void fill(int[][] array, int value) {
		for (int[] row : array)
			Arrays.fill(row, value);
	}

	}


import java.io.*;
import java.util.StringTokenizer;

public class B {
	BufferedReader in;
	StringTokenizer str;
	PrintWriter out;
	String SK;

	String next() throws IOException {
		while ((str == null) || (!str.hasMoreTokens())) {
			SK = in.readLine();
			if (SK == null)
				return null;
			str = new StringTokenizer(SK);
		}
		return str.nextToken();
	}

	int nextInt() throws IOException {
		return Integer.parseInt(next());
	}

	double nextDouble() throws IOException {
		return Double.parseDouble(next());
	}

	long nextLong() throws IOException {
		return Long.parseLong(next());
	}

	void solve() throws IOException {
		int n = nextInt();
		int[] h = new int[n];
		int x = nextInt();
		int y = nextInt();
		for (int i = 0; i < n; i++) {
			h[i] = nextInt();
		}
		int[][] d = new int[x + 1][2];
		int[][] res = new int[x + 1][2];
		for (int i = 0; i <= x; i++) {
			res[i][0] = res[i][1] = Integer.MAX_VALUE / 2;
		}
		if (x >= h[0]) {
			res[h[0]][0] = 0;
		}
		res[0][1] = 0;
		int sum = h[0];
		for (int k = 0; k < n - 1; k++) {
			for (int i = 0; i <= x; i++) {
				d[i][0] = res[i][0];
				d[i][1] = res[i][1];
				res[i][0] = Integer.MAX_VALUE / 2;
				res[i][1] = Integer.MAX_VALUE / 2;
			}
			sum += h[k + 1];
			for (int i = 0; i <= x; i++) {
				if (i + h[k + 1] <= x) {
					res[i + h[k + 1]][0] = Math.min(res[i + h[k + 1]][0],
							d[i][0]);
					res[i + h[k + 1]][0] = Math.min(res[i + h[k + 1]][0],
							d[i][1] + Math.min(h[k], h[k + 1]));
				}
				res[i][1] = Math.min(res[i][1],
						d[i][0] + Math.min(h[k], h[k + 1]));
				res[i][1] = Math.min(res[i][1], d[i][1]);
			}
		}
		int resul = Integer.MAX_VALUE / 2;
		for (int i = 0; i <= x; i++) {
			if (sum - i <= y) {
				resul = Math.min(resul, res[i][0]);
				resul = Math.min(resul, res[i][1]);
			}
		}
		if (resul == Integer.MAX_VALUE / 2) {
			out.println("-1");
		} else {
			out.println(resul);
		}

	}

	void run() throws IOException {
		in = new BufferedReader(new FileReader("input.txt"));
		out = new PrintWriter("output.txt");
		solve();
		out.close();
	}

	public static void main(String[] args) throws IOException {
		new B().run();
	}

}


import java.io.*;
import java.util.*;
import java.math.*;

import static java.lang.Math.*;

public class Main implements Runnable {

    void solve() throws Exception {
        int n = sc.nextInt();
        int a = sc.nextInt(), b = sc.nextInt();
        int[] h = new int[n + 1];
        for (int i = 0; i < n; i++) {
            h[i + 1] = sc.nextInt();
        }
        int[] sum = new int[n + 1];
        for (int i = 0; i <= n; i++) {
            if (i > 0) {
                sum[i] = sum[i - 1];
            }
            sum[i] += h[i];
        }
        int[][][] dp = new int[2][n + 1][a + 1];
        for (int i = 0; i < 2; i++) {
            for (int j = 0; j < n + 1; j++) {
                for (int k = 0; k < a + 1; k++) {
                    dp[i][j][k] = -1;
                }
            }
        }
        dp[0][0][a] = 0;
        dp[1][0][a] = 0;
        for (int i = 1; i <= n; i++) {
            for (int j = 0; j <= a; j++) {
                int greenleft = a + b - j - sum[i];
                if (greenleft < 0) {
                    continue;
                }
                for (int k = 0; k < 2; k++) {
                    int prevj, prevjj;
                    if (k == 0) {
                        prevj = j + h[i];
                        prevjj = greenleft;
                    } else {
                        prevj = j;
                        prevjj = greenleft + h[i];
                    }
                    if (prevj > a || prevjj > b) {
                        continue;
                    }
                    for (int kk = 0; kk < 2; kk++) {
                        if (dp[kk][i - 1][prevj] == -1) {
                            continue;
                        }
                        if (kk == k) {
                            dp[k][i][j] = dp[kk][i - 1][prevj];
                        } else {
                            dp[k][i][j] = dp[kk][i - 1][prevj] + min(h[i], h[i - 1]);
                        }
                    }
                }
            }
        }
        /*
        for (int i = 0; i <= n; i++) {
            for (int j = 0; j <= a; j++) {
                out.print("(" + dp[0][i][j] + " " + dp[1][i][j] + ") ");
            }
            out.println();
        }
        */
        int ans = -1;
        for (int k = 0; k < 2; k++) {
            for (int j = 0; j <= a; j++) {
                if (ans == -1 || dp[k][n][j] != -1 && dp[k][n][j] < ans) {
                    ans = dp[k][n][j];
                }
            }
        }
        out.println(ans);
    }

    BufferedReader in;
    PrintWriter out;
    FastScanner sc;

    static Throwable uncaught;

    @Override
    public void run() {
        try {
            //in = new BufferedReader(new InputStreamReader(System.in));
            //out = new PrintWriter(System.out);
            in = new BufferedReader(new FileReader("input.txt"));
            out = new PrintWriter(new FileWriter("output.txt"));
            sc = new FastScanner(in);
            solve();
        } catch (Throwable t) {
            Main.uncaught = t;
        } finally {
            out.close();
        }
    }

    public static void main(String[] args) throws Throwable {
        Thread t = new Thread(null, new Main(), "", 128 * 1024 * 1024);
        t.start();
        t.join();
        if (uncaught != null) {
            throw uncaught;
        }
    }

}

class FastScanner {

    BufferedReader reader;
    StringTokenizer strTok;

    public FastScanner(BufferedReader reader) {
        this.reader = reader;
    }

    public String nextToken() throws IOException {
        while (strTok == null || !strTok.hasMoreTokens()) {
            strTok = new StringTokenizer(reader.readLine());
        }
        return strTok.nextToken();
    }

    public int nextInt() throws IOException {
        return Integer.parseInt(nextToken());
    }

    public long nextLong() throws IOException {
        return Long.parseLong(nextToken());
    }

    public double nextDouble() throws IOException {
        return Double.parseDouble(nextToken());
    }

}


import java.io.*;
import java.util.*;
import java.math.*;

import static java.lang.Math.*;

public class Main implements Runnable {

    void solve() throws Exception {
        int n = sc.nextInt();
        int a = sc.nextInt(), b = sc.nextInt();
        int[] h = new int[n + 1];
        for (int i = 0; i < n; i++) {
            h[i + 1] = sc.nextInt();
        }
        int[] sum = new int[n + 1];
        for (int i = 0; i <= n; i++) {
            if (i > 0) {
                sum[i] = sum[i - 1];
            }
            sum[i] += h[i];
        }
        int[][][] dp = new int[2][n + 1][a + 1];
        for (int i = 0; i < 2; i++) {
            for (int j = 0; j < n + 1; j++) {
                for (int k = 0; k < a + 1; k++) {
                    dp[i][j][k] = -1;
                }
            }
        }
        dp[0][0][a] = 0;
        dp[1][0][a] = 0;
        for (int i = 1; i <= n; i++) {
            for (int j = 0; j <= a; j++) {
                int greenleft = a + b - j - sum[i];
                if (greenleft < 0) {
                    continue;
                }
                for (int k = 0; k < 2; k++) {
                    int prevj, prevjj;
                    if (k == 0) {
                        prevj = j + h[i];
                        prevjj = greenleft;
                    } else {
                        prevj = j;
                        prevjj = greenleft + h[i];
                    }
                    if (prevj > a || prevjj > b) {
                        continue;
                    }
                    for (int kk = 0; kk < 2; kk++) {
                        if (dp[kk][i - 1][prevj] == -1) {
                            continue;
                        }
                        int curval;
                        if (kk == k) {
                            curval = dp[kk][i - 1][prevj];
                        } else {
                             curval = dp[kk][i - 1][prevj] + min(h[i], h[i - 1]);
                        }
                        if (dp[k][i][j] == -1 || curval < dp[k][i][j]) {
                            dp[k][i][j] = curval;
                        }
                    }
                }
            }
        }
        /*
        for (int i = 0; i <= n; i++) {
            for (int j = 0; j <= a; j++) {
                out.print("(" + dp[0][i][j] + " " + dp[1][i][j] + ") ");
            }
            out.println();
        }
        */
        int ans = -1;
        for (int k = 0; k < 2; k++) {
            for (int j = 0; j <= a; j++) {
                if (ans == -1 || dp[k][n][j] != -1 && dp[k][n][j] < ans) {
                    ans = dp[k][n][j];
                }
            }
        }
        out.println(ans);
    }

    BufferedReader in;
    PrintWriter out;
    FastScanner sc;

    static Throwable uncaught;

    @Override
    public void run() {
        try {
            //in = new BufferedReader(new InputStreamReader(System.in));
            //out = new PrintWriter(System.out);
            in = new BufferedReader(new FileReader("input.txt"));
            out = new PrintWriter(new FileWriter("output.txt"));
            sc = new FastScanner(in);
            solve();
        } catch (Throwable t) {
            Main.uncaught = t;
        } finally {
            out.close();
        }
    }

    public static void main(String[] args) throws Throwable {
        Thread t = new Thread(null, new Main(), "", 128 * 1024 * 1024);
        t.start();
        t.join();
        if (uncaught != null) {
            throw uncaught;
        }
    }

}

class FastScanner {

    BufferedReader reader;
    StringTokenizer strTok;

    public FastScanner(BufferedReader reader) {
        this.reader = reader;
    }

    public String nextToken() throws IOException {
        while (strTok == null || !strTok.hasMoreTokens()) {
            strTok = new StringTokenizer(reader.readLine());
        }
        return strTok.nextToken();
    }

    public int nextInt() throws IOException {
        return Integer.parseInt(nextToken());
    }

    public long nextLong() throws IOException {
        return Long.parseLong(nextToken());
    }

    public double nextDouble() throws IOException {
        return Double.parseDouble(nextToken());
    }

}


import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.HashSet;
import java.util.StringTokenizer;

public class A {

    public static int[][][] dp;
    public static int[] h;
    public static int n;

    public static void main(String[] args) throws FileNotFoundException {
        Scanner in = new Scanner();
        //PrintWriter out = new PrintWriter(System.out);
        PrintWriter out = new PrintWriter(new FileOutputStream(new File("output.txt")));
        n = in.nextInt();
        int a = in.nextInt();
        int b = in.nextInt();
        // System.out.println(n +  " " + a + " " + b);
        h = new int[n];
        for (int i = 0; i < n; i++) {
            h[i] = in.nextInt();
        }
        dp = new int[2][n][a + 1];
        for (int[][] c : dp) {
            for (int[] d : c) {
                Arrays.fill(d, -2);
            }
        }
        int val = cal(0, a, b, 0);
        out.println(val);
        out.close();
    }

    static int cal(int last, int a, int b, int index) {
        /**
         * last = 0 -> blue, 1 ->red a ->blue, b -> red
         */
        if (index == n) {
            return 0;
        }
        if (dp[last][index][a] != -2) {
            return dp[last][index][a];
        }
        int result = -1;
        if (a >= h[index]) {
            int val = 0;
            if (last == 0) {
                val = cal(0, a - h[index], b, index + 1);
            } else {
                val = cal(0, a - h[index], b, index + 1);
                if (index > 0 && val != -1) {
                    val += Math.min(h[index], h[index - 1]);
                }
            }
            result = val;
        }
        if (b >= h[index]) {
            int val = 0;
            if (last == 1) {
                val = cal(1, a, b - h[index], index + 1);
            } else {
                val = cal(1, a, b - h[index], index + 1);
                if (index > 0 && val != -1) {
                    val += Math.min(h[index], h[index - 1]);
                }
            }
            if (val != -1) {
                if (result == -1 || result > val) {
                    result = val;
                }
            }
        }
        // System.out.println(last + " " + index + " " + result);
        return dp[last][index][a] = result;
    }

    public static long cal(long val) {
        long a = 0;
        long b = 1;
        if (val == 0 || val == 1) {
            return val;
        }
        while (b <= val) {
            long temp = b;
            b = a + b;
            a = temp;
        }
        return a;
    }

    static class Triple implements Comparable<Triple> {

        int s, f, t;

        public Triple(int s, int f, int t) {
            this.s = s;
            this.f = f;
            this.t = t;
        }

        @Override
        public int compareTo(Triple o) {
            return t - o.t;
        }
    }

    static double dist(Point a, Point b) {
        long total = (a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y);
        return Math.sqrt(total);
    }

    static class Point {

        int x, y;

        public Point(int x, int y) {
            this.x = x;
            this.y = y;

        }
    }

    public static boolean nextPer(int[] data) {
        int i = data.length - 1;
        while (i > 0 && data[i] < data[i - 1]) {
            i--;
        }
        if (i == 0) {
            return false;
        }
        int j = data.length - 1;
        while (data[j] < data[i - 1]) {
            j--;
        }
        int temp = data[i - 1];
        data[i - 1] = data[j];
        data[j] = temp;
        Arrays.sort(data, i, data.length);
        return true;
    }

    static class FT {

        int[] data;

        FT(int n) {
            data = new int[n];
        }

        void update(int index, int val) {
            // System.out.println("UPDATE INDEX " + index);
            while (index < data.length) {
                data[index] += val;
                index += index & (-index);

                //    System.out.println("NEXT " +index);
            }
        }

        int get(int index) {
            //  System.out.println("GET INDEX " + index);
            int result = 0;
            while (index > 0) {
                result += data[index];
                index -= index & (-index);
                // System.out.println("BACK " + index);
            }
            return result;
        }
    }

    static int gcd(int a, int b) {
        if (b == 0) {
            return a;
        } else {
            return gcd(b, a % b);
        }
    }

    static int pow(int a, int b) {
        if (b == 0) {
            return 1;
        }
        if (b == 1) {
            return a;
        }
        int val = pow(a, b / 2);
        if (b % 2 == 0) {

            return val * val;
        } else {
            return val * val * a;
        }
    }

//    static Point intersect(Point a, Point b, Point c) {
//        double D = cross(a, b);
//        if (D != 0) {
//            return new Point(cross(c, b) / D, cross(a, c) / D);
//        }
//        return null;
//    }
//
//    static Point convert(Point a, double angle) {
//        double x = a.x * cos(angle) - a.y * sin(angle);
//        double y = a.x * sin(angle) + a.y * cos(angle);
//        return new Point(x, y);
//    }
//    static Point minus(Point a, Point b) {
//        return new Point(a.x - b.x, a.y - b.y);
//    }
//
//    static Point add(Point a, Point b) {
//        return new Point(a.x + b.x, a.y + b.y);
//    }
//
//    static double cross(Point a, Point b) {
//        return a.x * b.y - a.y * b.x;
//
//
//    }
//
//    static class Point {
//
//        int x, y;
//
//        Point(int x, int y) {
//            this.x = x;
//            this.y = y;
//        }
//
//        @Override
//        public String toString() {
//            return "Point: " + x + " " + y;
//        }
//    }
    static class Scanner {

        BufferedReader br;
        StringTokenizer st;

        public Scanner() throws FileNotFoundException {
            //System.setOut(new PrintStream(new BufferedOutputStream(System.out), true));
            // br = new BufferedReader(new InputStreamReader(System.in));
            br = new BufferedReader(new FileReader(new File("input.txt")));
        }

        public String next() {

            while (st == null || !st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (Exception e) {
                    throw new RuntimeException();
                }
            }
            return st.nextToken();
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public double nextDouble() {
            return Double.parseDouble(next());
        }

        public String nextLine() {
            st = null;
            try {
                return br.readLine();
            } catch (Exception e) {
                throw new RuntimeException();
            }
        }

        public boolean endLine() {
            try {
                String next = br.readLine();
                while (next != null && next.trim().isEmpty()) {
                    next = br.readLine();
                }
                if (next == null) {
                    return true;
                }
                st = new StringTokenizer(next);
                return st.hasMoreTokens();
            } catch (Exception e) {
                throw new RuntimeException();
            }
        }
    }
}


/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

import java.util.*;
import java.io.*;
import java.math.*;
import java.lang.*;
/**
 *
 * @author calcsaransh
 */
public class Main {

    /**
     * @param args the command line arguments
     */
    static int red;
    static int green;
    static int h[];
    static int pref[];
    static int n;
    static int memo[][][];
    public static void main(String[] args) {
        // TODO code application logic here
        try
        {
            memo=new int[205][40005][2];
            Scanner pd=new Scanner(new FileReader("input.txt"));
            //Scanner pd=new Scanner(System.in);
            //BufferedReader br=new BufferedReader(new FileReader("input.txt"));
            PrintWriter pw=new PrintWriter(new BufferedWriter(new FileWriter("output.txt")));
            //PrintWriter pw=new PrintWriter(System.out);
            //System
            n=pd.nextInt();
            red=pd.nextInt();
            green=pd.nextInt();
            h=new int[n];
            pref=new int[n+1];
            for(int i=0;i<h.length;i++)
            {
                h[i]=pd.nextInt();
                pref[i+1]=pref[i]+h[i];
            }
            int ans=find(0,red,0);
            if(ans>=100000000)
                pw.println(-1);
            else
                pw.println(ans);
            pw.flush();
        }
        catch(Exception e)
        {
            e.printStackTrace();
        }
    }
    public static int find(int pos,int redleft,int last)
    {
        if(pos==n)
        {
            return 0;
        }
        int redused=red-redleft;
        int greenused=pref[pos]-redused;
        int greenleft=green-greenused;
        if(memo[pos][redleft][last]>0)return memo[pos][redleft][last]-1;
        //System.out.println(pos+" "+redused+" "+greenused+" "+greenleft);
        int min=1000000000;
        if(pos==0)
        {
            if(greenleft>=h[pos])
            {
                min=Math.min(min, find(pos+1,redleft,0));
            }
            if(redleft>=h[pos])
            {
                min=Math.min(min,find(pos+1,redleft-h[pos],1));
            }
        }
        else
        {
            if(greenleft>=h[pos])
            {
                if(last==0)
                {
                    min=Math.min(min, find(pos+1,redleft,0));
                }
                else
                {
                    min=Math.min(min, Math.min(h[pos], h[pos-1])+find(pos+1,redleft,0));
                }
            }
            if(redleft>=h[pos])
            {
                if(last==1)
                {
                    min=Math.min(min, find(pos+1,redleft-h[pos],1));
                }
                else
                {
                    min=Math.min(min, Math.min(h[pos], h[pos-1])+find(pos+1,redleft-h[pos],1));
                }
            }
        }
        memo[pos][redleft][last]=1+min;
        return min;
    }
}

class Parserdoubt {

    final private int BUFFER_SIZE = 1 << 17;
    private DataInputStream din;
    private byte[] buffer;
    private int bufferPointer, bytesRead;

    public Parserdoubt(InputStream in) {
        din = new DataInputStream(in);
        buffer = new byte[BUFFER_SIZE];
        bufferPointer = bytesRead = 0;
    }

    public String nextString() throws Exception {
        StringBuffer sb = new StringBuffer("");
        byte c = read();
        while (c <= ' ') {
            c = read();
        }
        do {
            sb.append((char) c);
            c = read();
        } while (c > ' ');
        return sb.toString();
    }

    public char nextChar() throws Exception {
        byte c = read();
        while (c <= ' ') {
            c = read();
        }
        return (char) c;
    }

    public int nextInt() throws Exception {
        int ret = 0;
        byte c = read();
        while (c <= ' ') {
            c = read();
        }
        boolean neg = c == '-';
        if (neg) {
            c = read();
        }
        do {
            ret = ret * 10 + c - '0';
            c = read();
        } while (c > ' ');
        if (neg) {
            return -ret;
        }
        return ret;
    }

    public long nextLong() throws Exception {
        long ret = 0;
        byte c = read();
        while (c <= ' ') {
            c = read();
        }
        boolean neg = c == '-';
        if (neg) {
            c = read();
        }
        do {
            ret = ret * 10 + c - '0';
            c = read();
        } while (c > ' ');
        if (neg) {
            return -ret;
        }
        return ret;
    }

    private void fillBuffer() throws Exception {
        bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
        if (bytesRead == -1) {
            buffer[0] = -1;
        }
    }

    private byte read() throws Exception {
        if (bufferPointer == bytesRead) {
            fillBuffer();
        }
        return buffer[bufferPointer++];
    }
}


/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

import java.util.*;
import java.io.*;
import java.math.*;
import java.lang.*;

/**
 *
 * @author calcsaransh
 */
public class Main {

    /**
     * @param args the command line arguments
     */
    static int red;
    static int green;
    static int h[];
    static int pref[];
    static int n;
    static int memo[][][];

    public static void main(String[] args) {
        // TODO code application logic here
        try {
            //System.out.println(Short.MAX_VALUE);
            memo = new int[2][40005][2];
            //Scanner pd = new Scanner(new FileReader("input.txt"));
            Scanner pd=new Scanner(System.in);
            //BufferedReader br=new BufferedReader(new FileReader("input.txt"));
            //PrintWriter pw = new PrintWriter(new BufferedWriter(new FileWriter("output.txt")));
            PrintWriter pw=new PrintWriter(System.out);
            //System
            n = pd.nextInt();
            red = pd.nextInt();
            green = pd.nextInt();
            h = new int[n];
            pref = new int[n + 1];
            for (int i = 0; i < h.length; i++) {
                h[i] = pd.nextInt();
                pref[i + 1] = pref[i] + h[i];
            }
            memo = new int[2][40005][2];
            for (int i = 0; i < 40005; i++) {
                for (int j = 0; j < 2; j++) {
                    memo[1][i][j] = 0;
                }
            }
            for (int pos = n - 1; pos >= 0; pos--) {
                for (int redleft = 0; redleft <= red; redleft++) {
                    for (int last = 0; last <= 1; last++) {
                        int redused = red - redleft;
                        int greenused = pref[pos] - redused;
                        int greenleft = green - greenused;

                    int min = 1000000000;
                    if (pos == 0) {
                        if (greenleft >= h[pos]) {
                            min = Math.min(min, memo[1][redleft][0]);
                        }
                        if (redleft >= h[pos]) {
                            min = Math.min(min, memo[1][ redleft - h[pos]] [1]);
                        }
                    } else {
                        if (greenleft >= h[pos]) {
                            if (last == 0) {
                                min = Math.min(min, memo[1][redleft][0]);
                            } else {
                                min = Math.min(min, Math.min(h[pos], h[pos - 1]) + memo[1][redleft][0]);
                            }
                        }
                        if (redleft >= h[pos]) {
                            if (last == 1) {
                                min = Math.min(min, memo[1][redleft-h[pos]][1]);
                            } else {
                                min = Math.min(min, Math.min(h[pos], h[pos - 1]) + memo[1][redleft-h[pos]][1]);
                            }
                        }
                    }
                 memo[0][redleft][last]=min;
                }
             }
                for (int redleft = 0; redleft <= red; redleft++) {
                    for (int last = 0; last <= 1; last++) {memo[1][redleft][last]=memo[0][redleft][last];
                    }}
            }
            int ans = memo[0][red][0];//find(0, red, 0);
            if (ans >= 100000000) {
                pw.println(-1);
            } else {
                pw.println(ans);
            }
            pw.flush();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static int find(int pos, int redleft, int last) {
        if (pos == n) {
            return 0;
        }
        int redused = red - redleft;
        int greenused = pref[pos] - redused;
        int greenleft = green - greenused;
        if (memo[pos][redleft][last] > 0) {
            return memo[pos][redleft][last] - 1;
        }
        //System.out.println(pos+" "+redused+" "+greenused+" "+greenleft);
        int min = 1000000000;
        if (pos == 0) {
            if (greenleft >= h[pos]) {
                min = Math.min(min, find(pos + 1, redleft, 0));
            }
            if (redleft >= h[pos]) {
                min = Math.min(min, find(pos + 1, redleft - h[pos], 1));
            }
        } else {
            if (greenleft >= h[pos]) {
                if (last == 0) {
                    min = Math.min(min, find(pos + 1, redleft, 0));
                } else {
                    min = Math.min(min, Math.min(h[pos], h[pos - 1]) + find(pos + 1, redleft, 0));
                }
            }
            if (redleft >= h[pos]) {
                if (last == 1) {
                    min = Math.min(min, find(pos + 1, redleft - h[pos], 1));
                } else {
                    min = Math.min(min, Math.min(h[pos], h[pos - 1]) + find(pos + 1, redleft - h[pos], 1));
                }
            }
        }
        memo[pos][redleft][last] = 1 + min;
        return min;
    }
}

class Parserdoubt {

    final private int BUFFER_SIZE = 1 << 17;
    private DataInputStream din;
    private byte[] buffer;
    private int bufferPointer, bytesRead;

    public Parserdoubt(InputStream in) {
        din = new DataInputStream(in);
        buffer = new byte[BUFFER_SIZE];
        bufferPointer = bytesRead = 0;
    }

    public String nextString() throws Exception {
        StringBuffer sb = new StringBuffer("");
        byte c = read();
        while (c <= ' ') {
            c = read();
        }
        do {
            sb.append((char) c);
            c = read();
        } while (c > ' ');
        return sb.toString();
    }

    public char nextChar() throws Exception {
        byte c = read();
        while (c <= ' ') {
            c = read();
        }
        return (char) c;
    }

    public int nextInt() throws Exception {
        int ret = 0;
        byte c = read();
        while (c <= ' ') {
            c = read();
        }
        boolean neg = c == '-';
        if (neg) {
            c = read();
        }
        do {
            ret = ret * 10 + c - '0';
            c = read();
        } while (c > ' ');
        if (neg) {
            return -ret;
        }
        return ret;
    }

    public long nextLong() throws Exception {
        long ret = 0;
        byte c = read();
        while (c <= ' ') {
            c = read();
        }
        boolean neg = c == '-';
        if (neg) {
            c = read();
        }
        do {
            ret = ret * 10 + c - '0';
            c = read();
        } while (c > ' ');
        if (neg) {
            return -ret;
        }
        return ret;
    }

    private void fillBuffer() throws Exception {
        bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
        if (bytesRead == -1) {
            buffer[0] = -1;
        }
    }

    private byte read() throws Exception {
        if (bufferPointer == bytesRead) {
            fillBuffer();
        }
        return buffer[bufferPointer++];
    }
}


/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

import java.util.*;
import java.io.*;
import java.math.*;
import java.lang.*;

/**
 *
 * @author calcsaransh
 */
public class Main {

    /**
     * @param args the command line arguments
     */
    static int red;
    static int green;
    static int h[];
    static int pref[];
    static int n;
    static int memo[][][];

    public static void main(String[] args) {
        // TODO code application logic here
        try {
            //System.out.println(Short.MAX_VALUE);
            memo = new int[2][40005][2];
            Scanner pd = new Scanner(new FileReader("input.txt"));
            //Scanner pd=new Scanner(System.in);
            //BufferedReader br=new BufferedReader(new FileReader("input.txt"));
            PrintWriter pw = new PrintWriter(new BufferedWriter(new FileWriter("output.txt")));
            //PrintWriter pw=new PrintWriter(System.out);
            //System
            n = pd.nextInt();
            red = pd.nextInt();
            green = pd.nextInt();
            h = new int[n];
            pref = new int[n + 1];
            for (int i = 0; i < h.length; i++) {
                h[i] = pd.nextInt();
                pref[i + 1] = pref[i] + h[i];
            }
            memo = new int[2][40005][2];
            for (int i = 0; i < 40005; i++) {
                for (int j = 0; j < 2; j++) {
                    memo[1][i][j] = 0;
                }
            }
            for (int pos = n - 1; pos >= 0; pos--) {
                for (int redleft = 0; redleft <= red; redleft++) {
                    for (int last = 0; last <= 1; last++) {
                        int redused = red - redleft;
                        int greenused = pref[pos] - redused;
                        int greenleft = green - greenused;

                    int min = 1000000000;
                    if (pos == 0) {
                        if (greenleft >= h[pos]) {
                            min = Math.min(min, memo[1][redleft][0]);
                        }
                        if (redleft >= h[pos]) {
                            min = Math.min(min, memo[1][ redleft - h[pos]] [1]);
                        }
                    } else {
                        if (greenleft >= h[pos]) {
                            if (last == 0) {
                                min = Math.min(min, memo[1][redleft][0]);
                            } else {
                                min = Math.min(min, Math.min(h[pos], h[pos - 1]) + memo[1][redleft][0]);
                            }
                        }
                        if (redleft >= h[pos]) {
                            if (last == 1) {
                                min = Math.min(min, memo[1][redleft-h[pos]][1]);
                            } else {
                                min = Math.min(min, Math.min(h[pos], h[pos - 1]) + memo[1][redleft-h[pos]][1]);
                            }
                        }
                    }
                 memo[0][redleft][last]=min;
                }
             }
                for (int redleft = 0; redleft <= red; redleft++) {
                    for (int last = 0; last <= 1; last++) {memo[1][redleft][last]=memo[0][redleft][last];
                    }}
            }
            int ans = memo[0][red][0];//find(0, red, 0);
            if (ans >= 100000000) {
                pw.println(-1);
            } else {
                pw.println(ans);
            }
            pw.flush();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static int find(int pos, int redleft, int last) {
        if (pos == n) {
            return 0;
        }
        int redused = red - redleft;
        int greenused = pref[pos] - redused;
        int greenleft = green - greenused;
        if (memo[pos][redleft][last] > 0) {
            return memo[pos][redleft][last] - 1;
        }
        //System.out.println(pos+" "+redused+" "+greenused+" "+greenleft);
        int min = 1000000000;
        if (pos == 0) {
            if (greenleft >= h[pos]) {
                min = Math.min(min, find(pos + 1, redleft, 0));
            }
            if (redleft >= h[pos]) {
                min = Math.min(min, find(pos + 1, redleft - h[pos], 1));
            }
        } else {
            if (greenleft >= h[pos]) {
                if (last == 0) {
                    min = Math.min(min, find(pos + 1, redleft, 0));
                } else {
                    min = Math.min(min, Math.min(h[pos], h[pos - 1]) + find(pos + 1, redleft, 0));
                }
            }
            if (redleft >= h[pos]) {
                if (last == 1) {
                    min = Math.min(min, find(pos + 1, redleft - h[pos], 1));
                } else {
                    min = Math.min(min, Math.min(h[pos], h[pos - 1]) + find(pos + 1, redleft - h[pos], 1));
                }
            }
        }
        memo[pos][redleft][last] = 1 + min;
        return min;
    }
}

class Parserdoubt {

    final private int BUFFER_SIZE = 1 << 17;
    private DataInputStream din;
    private byte[] buffer;
    private int bufferPointer, bytesRead;

    public Parserdoubt(InputStream in) {
        din = new DataInputStream(in);
        buffer = new byte[BUFFER_SIZE];
        bufferPointer = bytesRead = 0;
    }

    public String nextString() throws Exception {
        StringBuffer sb = new StringBuffer("");
        byte c = read();
        while (c <= ' ') {
            c = read();
        }
        do {
            sb.append((char) c);
            c = read();
        } while (c > ' ');
        return sb.toString();
    }

    public char nextChar() throws Exception {
        byte c = read();
        while (c <= ' ') {
            c = read();
        }
        return (char) c;
    }

    public int nextInt() throws Exception {
        int ret = 0;
        byte c = read();
        while (c <= ' ') {
            c = read();
        }
        boolean neg = c == '-';
        if (neg) {
            c = read();
        }
        do {
            ret = ret * 10 + c - '0';
            c = read();
        } while (c > ' ');
        if (neg) {
            return -ret;
        }
        return ret;
    }

    public long nextLong() throws Exception {
        long ret = 0;
        byte c = read();
        while (c <= ' ') {
            c = read();
        }
        boolean neg = c == '-';
        if (neg) {
            c = read();
        }
        do {
            ret = ret * 10 + c - '0';
            c = read();
        } while (c > ' ');
        if (neg) {
            return -ret;
        }
        return ret;
    }

    private void fillBuffer() throws Exception {
        bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
        if (bytesRead == -1) {
            buffer[0] = -1;
        }
    }

    private byte read() throws Exception {
        if (bufferPointer == bytesRead) {
            fillBuffer();
        }
        return buffer[bufferPointer++];
    }
}


/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

import java.util.*;
import java.io.*;
import java.math.*;
import java.lang.*;
/**
 *
 * @author calcsaransh
 */
public class Main {

    /**
     * @param args the command line arguments
     */
    static int red;
    static int green;
    static int h[];
    static int pref[];
    static int n;
    static int memo[][][];
    public static void main(String[] args) {
        // TODO code application logic here
        try
        {
            memo=new int[205][10005][2];
            Scanner pd=new Scanner(new FileReader("input.txt"));
            //Scanner pd=new Scanner(System.in);
            //BufferedReader br=new BufferedReader(new FileReader("input.txt"));
            PrintWriter pw=new PrintWriter(new BufferedWriter(new FileWriter("output.txt")));
            //PrintWriter pw=new PrintWriter(System.out);
            //System
            n=pd.nextInt();
            red=pd.nextInt();
            green=pd.nextInt();
            h=new int[n];
            pref=new int[n+1];
            for(int i=0;i<h.length;i++)
            {
                h[i]=pd.nextInt();
                pref[i+1]=pref[i]+h[i];
            }
            int ans=find(0,red,0);
            if(ans>=100000000)
                pw.println(-1);
            else
                pw.println(ans);
            pw.flush();
        }
        catch(Exception e)
        {
            e.printStackTrace();
        }
    }
    public static int find(int pos,int redleft,int last)
    {
        if(pos==n)
        {
            return 0;
        }
        int redused=red-redleft;
        int greenused=pref[pos]-redused;
        int greenleft=green-greenused;
        if(memo[pos][redleft][last]>0)return memo[pos][redleft][last]-1;
        //System.out.println(pos+" "+redused+" "+greenused+" "+greenleft);
        int min=1000000000;
        if(pos==0)
        {
            if(greenleft>=h[pos])
            {
                min=Math.min(min, find(pos+1,redleft,0));
            }
            if(redleft>=h[pos])
            {
                min=Math.min(min,find(pos+1,redleft-h[pos],1));
            }
        }
        else
        {
            if(greenleft>=h[pos])
            {
                if(last==0)
                {
                    min=Math.min(min, find(pos+1,redleft,0));
                }
                else
                {
                    min=Math.min(min, Math.min(h[pos], h[pos-1])+find(pos+1,redleft,0));
                }
            }
            if(redleft>=h[pos])
            {
                if(last==1)
                {
                    min=Math.min(min, find(pos+1,redleft-h[pos],1));
                }
                else
                {
                    min=Math.min(min, Math.min(h[pos], h[pos-1])+find(pos+1,redleft-h[pos],1));
                }
            }
        }
        memo[pos][redleft][last]=1+min;
        return min;
    }
}

class Parserdoubt {

    final private int BUFFER_SIZE = 1 << 17;
    private DataInputStream din;
    private byte[] buffer;
    private int bufferPointer, bytesRead;

    public Parserdoubt(InputStream in) {
        din = new DataInputStream(in);
        buffer = new byte[BUFFER_SIZE];
        bufferPointer = bytesRead = 0;
    }

    public String nextString() throws Exception {
        StringBuffer sb = new StringBuffer("");
        byte c = read();
        while (c <= ' ') {
            c = read();
        }
        do {
            sb.append((char) c);
            c = read();
        } while (c > ' ');
        return sb.toString();
    }

    public char nextChar() throws Exception {
        byte c = read();
        while (c <= ' ') {
            c = read();
        }
        return (char) c;
    }

    public int nextInt() throws Exception {
        int ret = 0;
        byte c = read();
        while (c <= ' ') {
            c = read();
        }
        boolean neg = c == '-';
        if (neg) {
            c = read();
        }
        do {
            ret = ret * 10 + c - '0';
            c = read();
        } while (c > ' ');
        if (neg) {
            return -ret;
        }
        return ret;
    }

    public long nextLong() throws Exception {
        long ret = 0;
        byte c = read();
        while (c <= ' ') {
            c = read();
        }
        boolean neg = c == '-';
        if (neg) {
            c = read();
        }
        do {
            ret = ret * 10 + c - '0';
            c = read();
        } while (c > ' ');
        if (neg) {
            return -ret;
        }
        return ret;
    }

    private void fillBuffer() throws Exception {
        bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
        if (bytesRead == -1) {
            buffer[0] = -1;
        }
    }

    private byte read() throws Exception {
        if (bufferPointer == bytesRead) {
            fillBuffer();
        }
        return buffer[bufferPointer++];
    }
}


import java.io.IOException;
import java.io.OutputStreamWriter;
import java.util.Arrays;
import java.io.BufferedWriter;
import java.util.InputMismatchException;
import java.io.FileOutputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.FileInputStream;
import java.io.Writer;
import java.math.BigInteger;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
	public static void main(String[] args) {
		InputStream inputStream;
		try {
			inputStream = new FileInputStream("input.txt");
		} catch (IOException e) {
			throw new RuntimeException(e);
		}
		OutputStream outputStream;
		try {
			outputStream = new FileOutputStream("output.txt");
		} catch (IOException e) {
			throw new RuntimeException(e);
		}
		InputReader in = new InputReader(inputStream);
		OutputWriter out = new OutputWriter(outputStream);
		TaskB solver = new TaskB();
		solver.solve(1, in, out);
		out.close();
	}
}

class TaskB {
	public void solve(int testNumber, InputReader in, OutputWriter out) {

        int n = in.nextInt();
        int a = in.nextInt();
        int b = in.nextInt();
        int h[] = in.nextIntArray(n);
        int i,j,k;
        int sum = 0;
        for(i=0;i<n;++i) sum+=h[i];
        if(sum>a+b){
            out.writeln(-1);
            return;
        }

        int d1[][] = new int[n][a+1];
        int d2[][] = new int[n][a+1];
        int inf = Integer.MAX_VALUE >> 1;

        for(int x[] : d1) Arrays.fill(x,inf);
        for(int x[] : d2) Arrays.fill(x,inf);

        d1[0][h[0]] = 0;
        d2[0][0] = 0;

        for(i=1;i<n;++i){
            for(j=0;j<=a;++j) {
                if(j>=h[i]) d1[i][j] = Math.min(d1[i][j], d2[i-1][j-h[i]] + Math.min(h[i],h[i-1]));
                if(j>=h[i]) d1[i][j] = Math.min(d1[i][j], d1[i-1][j-h[i]]);
                d2[i][j] = Math.min(d2[i][j], d1[i-1][j] + Math.min(h[i],h[i-1]));
                d2[i][j] = Math.min(d2[i][j], d2[i-1][j]);

               // out.writeln(i,' ',j," : ",d1[i][j],' ',d2[i][j]);
            }

        }

        int ans = inf;

        for(i=0;i<=a;++i) if(sum-i<=b){
            ans = Math.min(ans, d1[n-1][i]);
            ans = Math.min(ans, d2[n-1][i]);
        }

        out.writeln(ans==inf ? -1 : ans);
	}
}

class InputReader{
    private InputStream in;
    private byte buffer[] = new byte[1<<11];
    private int cur;
    private int end;

    public InputReader(InputStream stream){
        in = stream;
    }

    public int read(){
        if(end<0) throw new InputMismatchException();
        if(cur>=end){
            cur = 0;
            try{
                end = in.read(buffer);
            }catch(IOException e){
                throw new InputMismatchException();
            }
            if(end<=0) return -1;
        }
        return buffer[cur++];
    }

    public boolean isSpace(int c){
        return c==' ' || c=='\n' || c=='\r' || c=='\t' || c==-1;
    }

    public int nextInt(){
        int c = read(), res = 0, sign = 1;
        while(isSpace(c)) c = read();
        if(c=='-'){ sign = -1; c = read(); }
        do{
            if(c>'9' || c<'0') throw new InputMismatchException();
            res = res*10 + (c-'0');
            c = read();
        }while(!isSpace(c));
        return res*sign;
    }

    public int[] nextIntArray(int n){
        int res[] = new int[n];
        for(int i=0;i<n;++i) res[i] = nextInt();
        return res;
    }

    }

class OutputWriter{
    private PrintWriter out;

    public OutputWriter(Writer out){
        this.out = new PrintWriter(out);
    }

    public OutputWriter(OutputStream out){
        this.out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(out)));
    }

    public void close(){
        out.close();
    }

    public void write(Object ... o){
        for(Object x : o) out.print(x);
    }

    public void writeln(Object ... o){
        write(o);
        out.println();
    }
}


import java.io.IOException;
import java.io.OutputStreamWriter;
import java.util.Arrays;
import java.io.BufferedWriter;
import java.util.InputMismatchException;
import java.io.FileOutputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.FileInputStream;
import java.io.Writer;
import java.math.BigInteger;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
	public static void main(String[] args) {
		InputStream inputStream;
		try {
			inputStream = new FileInputStream("input.txt");
		} catch (IOException e) {
			throw new RuntimeException(e);
		}
		OutputStream outputStream;
		try {
			outputStream = new FileOutputStream("output.txt");
		} catch (IOException e) {
			throw new RuntimeException(e);
		}
		InputReader in = new InputReader(inputStream);
		OutputWriter out = new OutputWriter(outputStream);
		TaskB solver = new TaskB();
		solver.solve(1, in, out);
		out.close();
	}
}

class TaskB {
	public void solve(int testNumber, InputReader in, OutputWriter out) {

        int n = in.nextInt();
        int a = in.nextInt();
        int b = in.nextInt();
        int h[] = in.nextIntArray(n);
        int i,j,k;
        int sum = 0;
        for(i=0;i<n;++i) sum+=h[i];
        if(sum>a+b){
            out.writeln(-1);
            return;
        }

        int d1[][] = new int[n][a+1];
        int d2[][] = new int[n][a+1];
        int inf = Integer.MAX_VALUE >> 1;

        for(int x[] : d1) Arrays.fill(x,inf);
        for(int x[] : d2) Arrays.fill(x,inf);

        if(h[0]<=a) d1[0][h[0]] = 0;
        d2[0][0] = 0;

        for(i=1;i<n;++i){
            for(j=0;j<=a;++j) {
                if(j>=h[i]) d1[i][j] = Math.min(d1[i][j], d2[i-1][j-h[i]] + Math.min(h[i],h[i-1]));
                if(j>=h[i]) d1[i][j] = Math.min(d1[i][j], d1[i-1][j-h[i]]);
                d2[i][j] = Math.min(d2[i][j], d1[i-1][j] + Math.min(h[i],h[i-1]));
                d2[i][j] = Math.min(d2[i][j], d2[i-1][j]);

               // out.writeln(i,' ',j," : ",d1[i][j],' ',d2[i][j]);
            }

        }

        int ans = inf;

        for(i=0;i<=a;++i) if(sum-i<=b){
            ans = Math.min(ans, d1[n-1][i]);
            ans = Math.min(ans, d2[n-1][i]);
        }

        out.writeln(ans==inf ? -1 : ans);
	}
}

class InputReader{
    private InputStream in;
    private byte buffer[] = new byte[1<<11];
    private int cur;
    private int end;

    public InputReader(InputStream stream){
        in = stream;
    }

    public int read(){
        if(end<0) throw new InputMismatchException();
        if(cur>=end){
            cur = 0;
            try{
                end = in.read(buffer);
            }catch(IOException e){
                throw new InputMismatchException();
            }
            if(end<=0) return -1;
        }
        return buffer[cur++];
    }

    public boolean isSpace(int c){
        return c==' ' || c=='\n' || c=='\r' || c=='\t' || c==-1;
    }

    public int nextInt(){
        int c = read(), res = 0, sign = 1;
        while(isSpace(c)) c = read();
        if(c=='-'){ sign = -1; c = read(); }
        do{
            if(c>'9' || c<'0') throw new InputMismatchException();
            res = res*10 + (c-'0');
            c = read();
        }while(!isSpace(c));
        return res*sign;
    }

    public int[] nextIntArray(int n){
        int res[] = new int[n];
        for(int i=0;i<n;++i) res[i] = nextInt();
        return res;
    }

    }

class OutputWriter{
    private PrintWriter out;

    public OutputWriter(Writer out){
        this.out = new PrintWriter(out);
    }

    public OutputWriter(OutputStream out){
        this.out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(out)));
    }

    public void close(){
        out.close();
    }

    public void write(Object ... o){
        for(Object x : o) out.print(x);
    }

    public void writeln(Object ... o){
        write(o);
        out.println();
    }
}


import java.io.IOException;
import java.io.OutputStreamWriter;
import java.util.Arrays;
import java.io.BufferedWriter;
import java.util.InputMismatchException;
import java.io.FileOutputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.FileInputStream;
import java.io.Writer;
import java.math.BigInteger;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
	public static void main(String[] args) {
		InputStream inputStream;
		try {
			inputStream = new FileInputStream("input.txt");
		} catch (IOException e) {
			throw new RuntimeException(e);
		}
		OutputStream outputStream;
		try {
			outputStream = new FileOutputStream("output.txt");
		} catch (IOException e) {
			throw new RuntimeException(e);
		}
		InputReader in = new InputReader(inputStream);
		OutputWriter out = new OutputWriter(outputStream);
		TaskB solver = new TaskB();
		solver.solve(1, in, out);
		out.close();
	}
}

class TaskB {
	public void solve(int testNumber, InputReader in, OutputWriter out) {

        int n = in.nextInt();
        int a = in.nextInt();
        int b = in.nextInt();
        int h[] = in.nextIntArray(n);
        int i,j,k;
        int sum = 0;
        for(i=0;i<n;++i) sum+=h[i];
        if(sum>a+b){
            out.writeln(-1);
            return;
        }

        int d1[][] = new int[n][a+1];
        int d2[][] = new int[n][b+1];
        int inf = Integer.MAX_VALUE >> 1;

        for(int x[] : d1) Arrays.fill(x,inf);
        for(int x[] : d2) Arrays.fill(x,inf);

        d1[0][h[0]] = 0;
        d2[0][0] = 0;

        for(i=1;i<n;++i){
            for(j=0;j<=a;++j) {
                if(j>=h[i]) d1[i][j] = Math.min(d1[i][j], d2[i-1][j-h[i]] + Math.min(h[i],h[i-1]));
                if(j>=h[i]) d1[i][j] = Math.min(d1[i][j], d1[i-1][j-h[i]]);
                d2[i][j] = Math.min(d2[i][j], d1[i-1][j] + Math.min(h[i],h[i-1]));
                d2[i][j] = Math.min(d2[i][j], d2[i-1][j]);

               // out.writeln(i,' ',j," : ",d1[i][j],' ',d2[i][j]);
            }

        }

        int ans = inf;

        for(i=0;i<=a;++i) if(sum-i<=b){
            ans = Math.min(ans, d1[n-1][i]);
            ans = Math.min(ans, d2[n-1][i]);
        }

        out.writeln(ans==inf ? -1 : ans);
	}
}

class InputReader{
    private InputStream in;
    private byte buffer[] = new byte[1<<11];
    private int cur;
    private int end;

    public InputReader(InputStream stream){
        in = stream;
    }

    public int read(){
        if(end<0) throw new InputMismatchException();
        if(cur>=end){
            cur = 0;
            try{
                end = in.read(buffer);
            }catch(IOException e){
                throw new InputMismatchException();
            }
            if(end<=0) return -1;
        }
        return buffer[cur++];
    }

    public boolean isSpace(int c){
        return c==' ' || c=='\n' || c=='\r' || c=='\t' || c==-1;
    }

    public int nextInt(){
        int c = read(), res = 0, sign = 1;
        while(isSpace(c)) c = read();
        if(c=='-'){ sign = -1; c = read(); }
        do{
            if(c>'9' || c<'0') throw new InputMismatchException();
            res = res*10 + (c-'0');
            c = read();
        }while(!isSpace(c));
        return res*sign;
    }

    public int[] nextIntArray(int n){
        int res[] = new int[n];
        for(int i=0;i<n;++i) res[i] = nextInt();
        return res;
    }

    }

class OutputWriter{
    private PrintWriter out;

    public OutputWriter(Writer out){
        this.out = new PrintWriter(out);
    }

    public OutputWriter(OutputStream out){
        this.out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(out)));
    }

    public void close(){
        out.close();
    }

    public void write(Object ... o){
        for(Object x : o) out.print(x);
    }

    public void writeln(Object ... o){
        write(o);
        out.println();
    }
}


import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.io.StreamTokenizer;
import java.util.ArrayList;
import java.util.Arrays;

public class Main {
	private static StreamTokenizer in;
	private static PrintWriter out;
	static {
		try{
			in = new StreamTokenizer(new BufferedReader(new InputStreamReader(
					new FileInputStream("input.txt"))));
			out = new PrintWriter(new FileOutputStream("output.txt"));
		}
		catch(Exception e) {}

	/*
		in = new StreamTokenizer(new BufferedReader(new InputStreamReader(
				System.in)));
		out = new PrintWriter(System.out);
		*/
	}

	private static int nextInt() throws Exception {
		in.nextToken();
		return (int) in.nval;
	}

	private static String nextString() throws Exception {
		in.nextToken();
		return in.sval;
	}

	public static void main(String[] args) throws Exception {
		n = nextInt();
		r = nextInt();
		g = nextInt();
		for (int i=0; i<n; i++) {
			h[i] = nextInt();
			total += h[i];
		}

		/*if (g < r) {
			int t = g;
			g = r;
			r = t;
		}*/

		dp = new int[2][n+1][r+1];
		for (int[][] u : dp) {
			for (int[] v : u) {
				Arrays.fill(v, -2);
			}
		}
		out.println(f(0, 0, r));
		out.flush();
	}

	private static int[] h = new int[200];
	private static int[][][] dp;
	private static int n, total, g, r;

	private static int f(int last, int i, int r) { //last == 0 -> r, last == 1 -> g
		if (i == n) {
			if (g >= total - (Main.r - r)) {
				return 0;
			} else {
				return -1;
			}
		}
		if (dp[last][i][r] >= -1) {
			return dp[last][i][r];
		}

		// to red

		int ret = Integer.MAX_VALUE;

		if (r >= h[i]) {
			int a = f(0, i+1, r - h[i]);
			if (i != 0 && last == 1 && a >= 0) {
				a += Math.min(h[i-1], h[i]);
			}
			if (a >= 0) {
				ret = Math.min(ret, a);
			}
		}
		int a = f(1, i+1, r);
		if (i != 0 && last == 0 && a >= 0) {
			a += Math.min(h[i-1], h[i]);
		}
		if (a >= 0) {
			ret = Math.min(ret, a);
		}

		if (ret == Integer.MAX_VALUE) return dp[last][i][r] = -1;
		else return dp[last][i][r] = ret;
	}

}


import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Locale;
import java.util.StringTokenizer;

public class B {

	private void solve() throws IOException {
		int n = nextInt();
		int[] a = new int[2];
		a[0] = nextInt();
		a[1] = nextInt();
		int[][][] d = new int[2][n][a[0] + 1];

		for (int i = 0; i < 2; i++) {
			for (int j = 0; j < n; j++) {
				Arrays.fill(d[i][j], -1);
			}
		}

		int[] h = new int[n];
		int[] s = new int[n];
		for (int i = 0; i < n; i++) {
			h[i] = nextInt();
			if (i == 0) {
				s[i] = h[i];
			} else {
				s[i] = s[i - 1] + h[i];
			}
		}

		if (h[0] <= a[0]) {
			d[0][0][h[0]] = 0;
		}
		if (h[0] <= a[1]) {
			d[1][0][0] = 0;
		}

		for (int i = 0; i < n - 1; i++) {
			for (int j = 0; j < a[0]; j++) {
				int x = d[0][i][j];
				if (x != -1) {
					if (j + h[i + 1] <= a[0]) {
						d[0][i + 1][j + h[i + 1]] = x;
					}
					if (s[i + 1] - j <= a[1]) {
						d[1][i + 1][j] = x + Math.min(h[i], h[i + 1]);
					}
				}

				int y = d[1][i][j];
				if (y != -1) {
					if (j + h[i + 1] <= a[0]) {
						d[0][i + 1][j + h[i + 1]] = y + Math.min(h[i], h[i + 1]);
					}
					if (s[i + 1] - j <= a[1]) {
						d[1][i + 1][j] = y;
					}
				}
			}
		}

		int min = Integer.MAX_VALUE;
		for (int i = 0; i <= a[0]; i++) {
			if (d[0][n - 1][i] != -1) {
				min = Math.min(min, d[0][n - 1][i]);
			}
			if (d[1][n - 1][i] != -1) {
				min = Math.min(min, d[1][n - 1][i]);
			}
		}

		if (min == Integer.MAX_VALUE) {
			println("-1");
		} else {
			println(min);
		}
	}

	private String nextToken() throws IOException {
		while (tokenizer == null || !tokenizer.hasMoreTokens()) {
			tokenizer = new StringTokenizer(reader.readLine());
		}
		return tokenizer.nextToken();
	}

	private int nextInt() throws NumberFormatException, IOException {
		return Integer.parseInt(nextToken());
	}

	private double nextDouble() throws NumberFormatException, IOException {
		return Double.parseDouble(nextToken());
	}

	private long nextLong() throws IOException {
		return Long.parseLong(nextToken());
	}

	private void print(Object o) {
		writer.print(o);
	}

	private void println(Object o) {
		writer.println(o);
	}

	private void printf(String format, Object... o) {
		writer.printf(format, o);
	}

	public static void main(String[] args) {
		long time = System.currentTimeMillis();
		Locale.setDefault(Locale.US);
		new B().run();
		System.err.printf("%.3f\n", 1e-3 * (System.currentTimeMillis() - time));
	}

	BufferedReader reader;
	StringTokenizer tokenizer;
	PrintWriter writer;

	private void run() {
		try {
			reader = new BufferedReader(new InputStreamReader(System.in));
			writer = new PrintWriter(System.out);
			reader = new BufferedReader(new FileReader("input.txt"));
			writer = new PrintWriter("output.txt");

			solve();
			reader.close();
			writer.close();
		} catch (IOException e) {
			e.printStackTrace();
			System.exit(13);
		}
	}
}


import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Locale;
import java.util.StringTokenizer;

public class B {

	private void solve() throws IOException {
		int n = nextInt();
		int[] a = new int[2];
		a[0] = nextInt();
		a[1] = nextInt();
		int[][][] d = new int[2][n][a[0] + 1];

		for (int i = 0; i < 2; i++) {
			for (int j = 0; j < n; j++) {
				Arrays.fill(d[i][j], Integer.MAX_VALUE);
			}
		}

		int[] h = new int[n];
		int[] s = new int[n];
		for (int i = 0; i < n; i++) {
			h[i] = nextInt();
			if (i == 0) {
				s[i] = h[i];
			} else {
				s[i] = s[i - 1] + h[i];
			}
		}

		if (h[0] <= a[0]) {
			d[0][0][h[0]] = 0;
		}
		if (h[0] <= a[1]) {
			d[1][0][0] = 0;
		}

		for (int i = 0; i < n - 1; i++) {
			for (int j = 0; j < a[0]; j++) {
				int x = d[0][i][j];
				if (x != Integer.MAX_VALUE) {
					if (j + h[i + 1] <= a[0]) {
						d[0][i + 1][j + h[i + 1]] = Math.min(x, d[0][i + 1][j + h[i + 1]]);
					}
					if (s[i + 1] - j <= a[1]) {
						d[1][i + 1][j] = Math.min(x + Math.min(h[i], h[i + 1]), d[1][i + 1][j]);
					}
				}

				int y = d[1][i][j];
				if (y != Integer.MAX_VALUE) {
					if (j + h[i + 1] <= a[0]) {
						d[0][i + 1][j + h[i + 1]] = Math.min(y + Math.min(h[i], h[i + 1]), d[0][i + 1][j + h[i + 1]]);
					}
					if (s[i + 1] - j <= a[1]) {
						d[1][i + 1][j] = Math.min(d[1][i + 1][j], y);
					}
				}
			}
		}

		int min = Integer.MAX_VALUE;
		for (int i = 0; i <= a[0]; i++) {
			if (d[0][n - 1][i] != -1) {
				min = Math.min(min, d[0][n - 1][i]);
			}
			if (d[1][n - 1][i] != -1) {
				min = Math.min(min, d[1][n - 1][i]);
			}
		}

		if (min == Integer.MAX_VALUE) {
			println("-1");
		} else {
			println(min);
		}
	}

	private String nextToken() throws IOException {
		while (tokenizer == null || !tokenizer.hasMoreTokens()) {
			tokenizer = new StringTokenizer(reader.readLine());
		}
		return tokenizer.nextToken();
	}

	private int nextInt() throws NumberFormatException, IOException {
		return Integer.parseInt(nextToken());
	}

	private double nextDouble() throws NumberFormatException, IOException {
		return Double.parseDouble(nextToken());
	}

	private long nextLong() throws IOException {
		return Long.parseLong(nextToken());
	}

	private void print(Object o) {
		writer.print(o);
	}

	private void println(Object o) {
		writer.println(o);
	}

	private void printf(String format, Object... o) {
		writer.printf(format, o);
	}

	public static void main(String[] args) {
		long time = System.currentTimeMillis();
		Locale.setDefault(Locale.US);
		new B().run();
		System.err.printf("%.3f\n", 1e-3 * (System.currentTimeMillis() - time));
	}

	BufferedReader reader;
	StringTokenizer tokenizer;
	PrintWriter writer;

	private void run() {
		try {
			reader = new BufferedReader(new InputStreamReader(System.in));
			writer = new PrintWriter(System.out);
			reader = new BufferedReader(new FileReader("input.txt"));
			writer = new PrintWriter("output.txt");

			solve();
			reader.close();
			writer.close();
		} catch (IOException e) {
			e.printStackTrace();
			System.exit(13);
		}
	}
}


import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Locale;
import java.util.StringTokenizer;

public class B {

	private void solve() throws IOException {
		int n = nextInt();
		int[] a = new int[2];
		a[0] = nextInt();
		a[1] = nextInt();
		int[][][] d = new int[2][n][a[0] + 1];

		for (int i = 0; i < 2; i++) {
			for (int j = 0; j < n; j++) {
				Arrays.fill(d[i][j], Integer.MAX_VALUE);
			}
		}

		int[] h = new int[n];
		int[] s = new int[n];
		for (int i = 0; i < n; i++) {
			h[i] = nextInt();
			if (i == 0) {
				s[i] = h[i];
			} else {
				s[i] = s[i - 1] + h[i];
			}
		}

		if (h[0] <= a[0]) {
			d[0][0][h[0]] = 0;
		}
		if (h[0] <= a[1]) {
			d[1][0][0] = 0;
		}

		for (int i = 0; i < n - 1; i++) {
			for (int j = 0; j <= a[0]; j++) {
				int x = d[0][i][j];
				if (x != Integer.MAX_VALUE) {
					if (j + h[i + 1] <= a[0]) {
						d[0][i + 1][j + h[i + 1]] = Math.min(x, d[0][i + 1][j + h[i + 1]]);
					}
					if (s[i + 1] - j <= a[1]) {
						d[1][i + 1][j] = Math.min(x + Math.min(h[i], h[i + 1]), d[1][i + 1][j]);
					}
				}

				int y = d[1][i][j];
				if (y != Integer.MAX_VALUE) {
					if (j + h[i + 1] <= a[0]) {
						d[0][i + 1][j + h[i + 1]] = Math.min(y + Math.min(h[i], h[i + 1]), d[0][i + 1][j + h[i + 1]]);
					}
					if (s[i + 1] - j <= a[1]) {
						d[1][i + 1][j] = Math.min(d[1][i + 1][j], y);
					}
				}
			}
		}

		int min = Integer.MAX_VALUE;
		for (int i = 0; i <= a[0]; i++) {
			min = Math.min(min, d[0][n - 1][i]);
			min = Math.min(min, d[1][n - 1][i]);
		}

		if (min == Integer.MAX_VALUE) {
			println("-1");
		} else {
			println(min);
		}
	}

	private String nextToken() throws IOException {
		while (tokenizer == null || !tokenizer.hasMoreTokens()) {
			tokenizer = new StringTokenizer(reader.readLine());
		}
		return tokenizer.nextToken();
	}

	private int nextInt() throws NumberFormatException, IOException {
		return Integer.parseInt(nextToken());
	}

	private double nextDouble() throws NumberFormatException, IOException {
		return Double.parseDouble(nextToken());
	}

	private long nextLong() throws IOException {
		return Long.parseLong(nextToken());
	}

	private void print(Object o) {
		writer.print(o);
	}

	private void println(Object o) {
		writer.println(o);
	}

	private void printf(String format, Object... o) {
		writer.printf(format, o);
	}

	public static void main(String[] args) {
		long time = System.currentTimeMillis();
		Locale.setDefault(Locale.US);
		new B().run();
		System.err.printf("%.3f\n", 1e-3 * (System.currentTimeMillis() - time));
	}

	BufferedReader reader;
	StringTokenizer tokenizer;
	PrintWriter writer;

	private void run() {
		try {
			reader = new BufferedReader(new InputStreamReader(System.in));
			writer = new PrintWriter(System.out);
			reader = new BufferedReader(new FileReader("input.txt"));
			writer = new PrintWriter("output.txt");

			solve();
			reader.close();
			writer.close();
		} catch (IOException e) {
			e.printStackTrace();
			System.exit(13);
		}
	}
}


import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.io.StreamTokenizer;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.TreeSet;

public class B {

    private static int n,a,b;
    private static int[] h;
    private static int count = 0;

    private static int[] pre;

    private static int[][][] dp;

    private static int dp(int pos, int spa, int last) {

        int losta = a - spa;
        int lostb = pre[pos] - h[pos] - (a - spa);
        int spb = b - lostb;

        if(spa < 0 || spb < 0)
            return -2;

        if(dp[pos][spa][last] != -1)
            return dp[pos][spa][last];

        if(pos == n-1) {
            if(last == 1) {
                if(spa >= h[pos]) {
                    return dp[pos][spa][last] = 0;
                } else if(spb >= h[pos]) {
                    return dp[pos][spa][last] = Math.min(h[pos], h[pos-1]);
                } else {
                    return dp[pos][spa][last] = -2;
                }
            } else {
                if(spb >= h[pos]) {
                    return dp[pos][spa][last] = 0;
                } else if(spa >= h[pos]) {
                    return dp[pos][spa][last] = Math.min(h[pos], h[pos-1]);
                } else {
                    return dp[pos][spa][last] = -2;
                }
            }
        }

        int c1 = dp(pos+1, spa-h[pos], 1);
        int c2 = dp(pos+1, spa, 0);

        if(c1 != -2)
            c1 += last == 0 ? Math.min(h[pos], h[pos-1]) : 0;

        if(c2 != -2)
            c2 += last == 1 ? Math.min(h[pos], h[pos-1]) : 0;

        if(c1 == -2 && c2 == -2)
            return dp[pos][spa][last] = -2;

        if(c1 == -2)
            return dp[pos][spa][last] = c2;

        if(c2 == -2)
            return dp[pos][spa][last] = c1;

        return dp[pos][spa][last] = Math.min(c1, c2);
    }

    public static void main(String[] argv) throws Exception {
        n = nextInt();
        a = nextInt();
        b = nextInt();

        h = new int[n];
        pre = new int[n];
        for(int i = 0; i<n; i++) {
            h[i] = nextInt();
            count += h[i];
            for(int j = 0; j<=i; j++) {
                pre[i] += h[j];
            }
        }

        if(a + b < count)
            exit(-1);

        if(n == 1)
            exit((a>=count || b>=count) ? 0 : -1);

        dp = new int[n+1][a+1][3];
        for(int i = 0; i<dp.length; i++) {
            for(int j = 0; j<a+1; j++) {
                Arrays.fill(dp[i][j], -1);
            }
        }
        for(int j = 0; j<a+1; j++) {
            dp[0][j] = new int[3];
            Arrays.fill(dp[0][j], -1);
        }

        int best = dp(0, a, 2);
        if(best == -2)
            exit(-1);

        println(best);
    }

    // ///////////////////////////////////////////////////
    // IO
    // ///////////////////////////////////////////////////
    private static StreamTokenizer in;
    private static BufferedReader inB;
    private static PrintWriter out;

    private static int nextInt() throws Exception {
        in.nextToken();
        return (int) in.nval;
    }

    private static String nextString() throws Exception {
        in.nextToken();
        return in.sval;
    }

    private static final boolean files = true;

    private static final String fileInputName = "input.txt";
    private static final String fileOutputName = "output.txt";

    static {
        try {
            inB = (new BufferedReader(new InputStreamReader(
                    files ? new FileInputStream(fileInputName) : System.in)));
            out = new PrintWriter(files ? new FileOutputStream(fileOutputName)
                    : System.out);
        } catch (Exception e) {
            e.printStackTrace();
        }
        in = new StreamTokenizer(inB);
    }

    // ///////////////////////////////////////////////////

    // /////////////////////////////////////////////////
    // Pre - written
    // /////////////////////////////////////////////////
    private static void println(Object o) throws Exception {
        out.println(o);
        out.flush();
    }

    private static void exit() {
        System.exit(0);
    }

    private static void exit(Object o) throws Exception {
        println(o);
        exit();
    }
    // /////////////////////////////////////////////////
}


import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.io.StreamTokenizer;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.TreeSet;

public class B {

    private static int n,a,b;
    private static int[] h;
    private static int count = 0;

    private static int[] pre;

    private static int[][][] dp;

    private static int dp(int pos, int spa, int last) {

        int losta = a - spa;
        int lostb = pre[pos] - h[pos] - (a - spa);
        int spb = b - lostb;

        if(spa < 0 || spb < 0)
            return -2;

        if(dp[pos][spa][last] != -1)
            return dp[pos][spa][last];

        if(pos == n-1) {
            if(last == 1) {
                if(spa >= h[pos]) {
                    return dp[pos][spa][last] = 0;
                } else if(spb >= h[pos]) {
                    return dp[pos][spa][last] = Math.min(h[pos], h[pos-1]);
                } else {
                    return dp[pos][spa][last] = -2;
                }
            } else {
                if(spb >= h[pos]) {
                    return dp[pos][spa][last] = 0;
                } else if(spa >= h[pos]) {
                    return dp[pos][spa][last] = Math.min(h[pos], h[pos-1]);
                } else {
                    return dp[pos][spa][last] = -2;
                }
            }
        }

        int c1 = dp(pos+1, spa-h[pos], 1);
        int c2 = dp(pos+1, spa, 0);

        if(c1 != -2)
            c1 += last == 0 ? Math.min(h[pos], h[pos-1]) : 0;

        if(c2 != -2)
            c2 += last == 1 ? Math.min(h[pos], h[pos-1]) : 0;

        if(c1 == -2 && c2 == -2)
            return dp[pos][spa][last] = -2;

        if(c1 == -2)
            return dp[pos][spa][last] = c2;

        if(c2 == -2)
            return dp[pos][spa][last] = c1;

        return dp[pos][spa][last] = Math.min(c1, c2);
    }

    public static void main(String[] argv) throws Exception {
        n = nextInt();
        a = nextInt();
        b = nextInt();

        h = new int[n];
        pre = new int[n];
        for(int i = 0; i<n; i++) {
            h[i] = nextInt();
            count += h[i];
            for(int j = 0; j<=i; j++) {
                pre[i] += h[j];
            }
        }

        if(a + b < count)
            exit(-1);

        if(n == 1)
            exit(0);

        dp = new int[n+1][40001][3];
        for(int i = 0; i<dp.length; i++) {
            for(int j = 0; j<40001; j++) {
                Arrays.fill(dp[i][j], -1);
            }

        }

        int best = dp(0, a, 2);
        if(best == -2)
            exit(-1);

        println(best);
    }

    // ///////////////////////////////////////////////////
    // IO
    // ///////////////////////////////////////////////////
    private static StreamTokenizer in;
    private static BufferedReader inB;
    private static PrintWriter out;

    private static int nextInt() throws Exception {
        in.nextToken();
        return (int) in.nval;
    }

    private static String nextString() throws Exception {
        in.nextToken();
        return in.sval;
    }

    private static final boolean files = true;

    private static final String fileInputName = "input.txt";
    private static final String fileOutputName = "output.txt";

    static {
        try {
            inB = (new BufferedReader(new InputStreamReader(
                    files ? new FileInputStream(fileInputName) : System.in)));
            out = new PrintWriter(files ? new FileOutputStream(fileOutputName)
                    : System.out);
        } catch (Exception e) {
            e.printStackTrace();
        }
        in = new StreamTokenizer(inB);
    }

    // ///////////////////////////////////////////////////

    // /////////////////////////////////////////////////
    // Pre - written
    // /////////////////////////////////////////////////
    private static void println(Object o) throws Exception {
        out.println(o);
        out.flush();
    }

    private static void exit() {
        System.exit(0);
    }

    private static void exit(Object o) throws Exception {
        println(o);
        exit();
    }
    // /////////////////////////////////////////////////
}