program groupa(input,output);
var
n,i,l,r,duo,shao,ans,t:longint;
gp:array[1..10000]of longint;
begin
assign(input,'groupa.in');
reset(input);
assign(output,'groupa.out');
rewrite(output);
readln(n);
for i:=1 to n do
read(gp[i]);
readln(l,r);
for i:=1 to n do
if gp[i]>r then
begin
duo:=duo+gp[i]-r;
gp[i]:=r;
end
else if gp[i]<l then
begin
shao:=shao+l-gp[i];
gp[i]:=l;
end;
if duo>shao then
begin
duo:=duo-shao;
ans:=shao;
shao:=0;
end
else
begin
shao:=shao-duo;
ans:=duo;
duo:=0;
end;
for i:=1 to n do
if (shao>0)and(gp[i]>l) then
begin
t:=gp[i]-l;
if t>shao then
t:=shao;
shao:=shao-t;
ans:=ans+t;
end
else if (duo>0)and(gp[i]<r) then
begin
t:=r-gp[i];
if t>duo then
t:=duo;
duo:=duo-t;
ans:=ans+t;
end;
if (shao=0)and(duo=0) then
writeln(ans)
else
writeln(-1);
close(input);
close(output);
end.