{
TASK: water
LANG: PASCAL
}

program water;

type
ran1 = 0..15;
ran2 = 0..255;

var
a:array[ran1] of record v:ran2; d1,d2:ran2 end;
//w:array[ran2,ran2,ran2] of boolean;
v:ran2;
k:ran1;
res:word;
p:word;

procedure readIt;
var i:ran1;
begin
readln(v,k);
for i:=1 to 3 do read(a[i].d1,a[i].d2);
readln;
end;

procedure go(s1,s2,s3,d:ran2);
var i,j,q:ran2;
s,x:array[ran1] of ran2;
begin

if d > k then exit;

s[1]:=s1;s[2]:=s2;s[3]:=s3;

//writeln(d,': ',s[1],' ',s[2],' ',s[3]);
//if (s1=10) and (s2=10) and (d = 1) then p:=1;
//if p > 0 then p:=p+1;
//if p = 20 then readln;

for q:=1 to 3 do begin
if s[q] = 1 then begin
res:=res+1;
exit;
end;
end;

for i:=1 to 3 do
for j:=1 to 3 do begin

if (s[j] <= a[j].d1) and (s[i] > 0) and (s[i] >= a[j].d1-s[j]) and (i <> j) then begin
for q:=1 to 3 do x[q]:=s[q];
x[i]:=s[i]-a[j].d1+s[j]; x[j]:=a[j].d1;
go(x[1],x[2],x[3],d+1);
end;

if (s[j] <= a[j].d2) and (s[i] > 0) and (s[i] >= a[j].d2-s[j]) and (i <> j) then begin
for q:=1 to 3 do x[q]:=s[q];
x[i]:=s[i]-a[j].d2+s[j]; x[j]:=a[j].d2;
go(x[1],x[2],x[3],d+1);
end;

if (s[i] >= a[i].d1) and  (s[i] > 0)  and (i <> j) then begin
for q:=1 to 3 do x[q]:=s[q];
x[i]:=a[i].d1; x[j]:=s[j]+s[i]-a[i].d1;
go(x[1],x[2],x[3],d+1);
end;

if (s[i] >= a[i].d2) and  (s[i] > 0) and (i <> j) then begin
for q:=1 to 3 do x[q]:=s[q];
x[i]:=a[i].d2; x[j]:=s[j]+s[i]-a[i].d2;
go(x[1],x[2],x[3],d+1);
end;


end;


end;

begin
readIt;
res:=0;
go(v, 0, 0, 0);
writeln(res);
end.
