{
TASK:water
LANG:PASCAL
}
//{$I-,Q-,R-,S-}
const
   HEAPSIZE = 32;
   MaxV = 200;
type
   Tarr = array[1..3] of longint;
   TType = TArr;
   Theap = object
      a : array[1..HeapSize] of TType;
      n : longint;
      i,j : longint;
      d : TType;
      procedure Push(var k : TType);
      procedure pop(var k : TType);
      procedure swap(ii,jj : longint);
      function cmp(ii,jj : longint) : boolean;
   end;
      function Theap.cmp(ii,jj : longint) : boolean;
      begin
         if a[ii,1]>a[jj,1] then
            cmp:=true
         else
            begin
               if a[ii,1]=a[jj,1] then
                  begin
                     if a[ii,2]>a[jj,2] then
                        cmp:=true
                     else
                        begin
                           if a[ii,2]=a[jj,2] then
                              begin
                                 if a[ii,3]>=a[jj,3] then
                                    cmp:=true
                                 else
                                     cmp:=false;
                              end
                           else
                              cmp:=false;
                        end;

                  end
               else
                  cmp:=false;
            end;

      end;
      procedure Theap.Push(var k : TType);
      begin
         inc(n);
         a[n]:=k;
         i:=n;
         while (i>1)and(cmp(i,i shr 1)) do
            begin
               swap(i,i shr 1);
               i:= i shr 1;
            end;
      end;
      procedure Theap.pop(var k : TType);
      begin
         k:=a[1];
         a[1]:=a[n];
         dec(n);
         i:=1;
         j:=i shl 1;
         while j<=n do
            begin
               if (j<n)and(cmp(j+1,j)) then
                  inc(j);
               if cmp(j,i) then
                  begin
                     swap(i,j);
                     i:=j;
                     j:=i shl 1;
                  end
               else
                  exit;
            end
      end;
      procedure Theap.swap(ii,jj : longint);
      begin
         d:=a[ii];
         a[ii]:=a[jj];
         a[jj]:=d;
      end;

var
   a : array[1..3,0..2] of longint;
   m : array[1..5,0..MaxV,0..MaxV,0..MaxV] of word;
   us : array[1..5,0..MaxV,0..MaxV,0..MaxV] of boolean;
   v,k,ans : longint;

procedure rec(k : byte;v : TArr);
var
   i,j,o,br,q : byte;
   nv2 : THeap;
   nv : TArr;
   res : longint;
begin
   res:=0;
   nv2.n:=0;
   if k<6 then
   for i:=1 to 3 do if v[i]=1 then
      begin
         us[k,v[1],v[2],v[3]]:=true;
         m[k,v[1],v[2],v[3]]:=1;
         exit;
      end;
   br:=0;
   for i:=1 to 2 do
      for j:=i+1 to 3 do
         for o:= 0 to 2 do
            begin
               nv:=v;
               nv[i]:=v[i]+v[j] - a[j,o];
               nv[j]:=a[j,o];

               if (nv[i]>=0)and(nv[j]>=0) then
                    nv2.push(nv);

               nv:=v;
               nv[j]:=v[i]+v[j] - a[i,o];
               nv[i]:=a[i,o];

               if (nv[i]>=0)and(nv[j]>=0) then
                 nv2.push(nv);

            end;
   while nv2.n>1 do
      begin
         nv2.pop(nv);
         if ((nv2.a[1,1]<>nv[1]) or (nv2.a[1,2]<>nv[2]))
             and((v[1]<>nv[1])or(v[2]<>nv[2])) then
            begin
               if (not us[k-1,nv[1],nv[2],nv[3]])and(k>1) then
                  rec(k-1,nv);
               if k = 1 then
                  begin
                     for q:=1 to 3 do if nv[q]=1 then
                        begin
                           res:=res+1;
                           break;
                        end;
                  end
               else
               res:=res+m[k-1,nv[1],nv[2],nv[3]];
            end;
      end;
   nv2.pop(nv);
   if (not us[k-1,nv[1],nv[2],nv[3]])and(k>1) then
      rec(k-1,nv);
   if k = 1 then
      begin
         for q:=1 to 3 do if nv[q]=1 then
            begin
               res:=res+1;
               break;
            end;
      end
   else
     res:=res+m[k-1,nv[1],nv[2],nv[3]];
   if k<6 then
      begin
   us[k,v[1],v[2],v[3]]:=true;
   m [k,v[1],v[2],v[3]]:=res;
      end
   else
      ans:=res;


end;
var
   l : Tarr;
begin

   readln(v,k);
   readln(a[1,1],a[1,2],a[2,1],a[2,2],a[3,1],a[3,2]);
   l[1]:=v;
   rec(k,l);
   if k<6 then writeln(m[k,v,0,0])
      else writeln(ans);

end.
