const fi='daycon.inp';
fo='daycon.out';
maxn=round(1e5)+5;
var n,s,i,j,sum,k,dem,tong:longint;
a,dem: array [1..maxn] of longint;
procedure nhap;
var i:longint;
begin
assign(input,fi);
reset(input);
readln(n,m);
for i:=1 to n do
readln(a[i]);
close(input);
end;
type
tlist = array[1..max] of longint;
procedure qsortAB(var a,b : tlist);
procedure sort(l,r: longint);
var
i,j,x,y: longint;
begin
i:=l;
j:=r;
x:=a[(l+r) div 2];
while(i<=j) do
begin
while a[i]<x do
inc(i);
while x<a[j] do
dec(j);
if not(i>j) then
begin
y:=a[i]; a[i]:=a[j]; a[j]:=y;
y:=b[i]; b[i]:=b[j]; b[j]:=y;
inc(i);
j:=j-1;
end;
end;
if l<j then
sort(l,j);
if i<r then
sort(i,r);
end;
begin
sort(1,max);
end;
procedure xuly;
var c:longint;
begin
for i:=1 to n do
begin
sum:=i;
for j := i+1 to n-1 do
begin
if (sum<m) then sum:=sum+a[j]
else if (sum>m) then begin sum :=0; break; end
else if (sum = m) then begin k:=k+1; a[k]:=a[j]; break; end;
end;
end;
end;
procedure xuat;
begin
assign(output,fo);
rewrite(output);
if k=0 then write(-1);
for i:=1 to k do
begin
tong:=0;
while tong<m do
begin
dec(a[i]);
tong:=tong+a[i];
inc(dem);
end;
end;
write(dem);
close(output);
end;
begin
nhap;
xuly;
xuat;
end.