{
TASK:water
LANG:PASCAL
}


type el = record
           d1, d2, val : byte;
          end;


var used : array[0..200, 0..200, 0..200] of byte;
    v, i, j, k, l, o, p, m, n : longint;
    m1, m2, m3 : el;
    len, answer : longint;


procedure input;
var f : text;
 begin
  assign(f, '');
  reset(f);
  readln(f, v, k);
  readln(f, m1.d1, m1.d2, m2.d1, m2.d2, m3.d1, m3.d2);
  close(f);
  m1.val := v;
  if m1.d1 > m1.d2 then
    begin
     p := m1.d1;
     m1.d1 := m1.d2;
     m1.d2 := p;
    end;
  if m2.d1 > m2.d2 then
    begin
     p := m2.d1;
     m2.d1 := m2.d2;
     m2.d2 := p;
    end;
  if m3.d1 > m3.d2 then
    begin
     p := m3.d1;
     m3.d1 := m3.d2;
     m3.d2 := p;
    end;

 end;


procedure count(v1, v2, v3 : byte; w : byte);
 begin
  used[v1, v2, v3] := 1;
  if (v1 = 1) or (v2 = 1) or (v3 = 1) then
    begin
     inc(answer);
    end
  else if w < k then
    begin
     {ab}
     if v1 > 0 then
       begin
        if (v2 < m2.d1) and (v1 >= m2.d1 - v2) and (used[v1 - (m2.d1 - v2), m2.d1, v3] = 0) then count(v1 - (m2.d1 - v2), m2.d1, v3, w + 1);
        if (v2 < m2.d2) and (v1 >= m2.d2 - v2) and (used[v1 - (m2.d2 - v2), m2.d2, v3] = 0) then count(v1 - (m2.d2 - v2), m2.d2, v3, w + 1);
        if (v1 >= m1.d1) and (used[m1.d1, v2 + (v1 - m1.d1), v3] = 0) then count(m1.d1, v2 + (v1 - m1.d1), v3, w + 1);
        if (v1 >= m1.d2) and (used[m1.d2, v2 + (v1 - m1.d2), v3] = 0) then count(m1.d2, v2 + (v1 - m1.d2), v3, w + 1);
        if (used[0, v1 + v2, v3] = 0) then count(0, v1 + v2, v3, w + 1);
       end;
     {ac}
     if v1 > 0 then
       begin
        if (v3 < m3.d1) and (v1 >= m3.d1 - v3) and (used[v1 - (m3.d1 - v3), v2, m3.d1] = 0) then count(v1 - (m3.d1 - v3), v2, m3.d1, w + 1);
        if (v3 < m3.d2) and (v1 >= m3.d2 - v3) and (used[v1 - (m3.d2 - v3), v2, m3.d2] = 0) then count(v1 - (m3.d2 - v3), v2, m3.d2, w + 1);
        if (v1 >= m1.d1) and (used[m1.d1, v2, v3 + (v1 - m1.d1)] = 0) then count(m1.d1, v2, v3 + (v1 - m1.d1), w + 1);
        if (v1 >= m1.d2) and (used[m1.d2, v2, v3 + (v1 - m1.d2)] = 0) then count(m1.d2, v2, v3 + (v1 - m1.d2), w + 1);
        if (used[0, v2, v1 + v3] = 0) then count(0, v2, v1 + v3, w + 1);
       end;
     {bc}
     if v2 > 0 then
       begin
        if (v3 < m3.d1) and (v2 >= m3.d1 - v3) and (used[v1, v2 - (m3.d1 - v3), m3.d1] = 0) then count(v1, v2 - (m3.d1 - v3), m3.d1, w + 1);
        if (v3 < m3.d2) and (v2 >= m3.d2 - v3) and (used[v1, v2 - (m3.d2 - v3), m3.d2] = 0) then count(v1, v2 - (m3.d2 - v3), m3.d2, w + 1);
        if (v2 >= m2.d1) and (used[v1, m2.d1, v3 + (v2 - m2.d1)] = 0) then count(v1, m2.d1, v3 + (v2 - m2.d1), w + 1);
        if (v2 >= m2.d2) and (used[v1, m2.d2, v3 + (v2 - m2.d2)] = 0) then count(v1, m2.d2, v3 + (v2 - m2.d2), w + 1);
        if (used[v1, 0, v2 + v3] = 0) then count(v1, 0, v2 + v3, w + 1);
       end;
     {cb}
     if v3 > 0 then
       begin
        if (v2 < m2.d1) and (v3 >= m2.d1 - v2) and (used[v1, m2.d1, v3 - (m2.d1 - v2)] = 0) then count(v1, m2.d1, v3 - (m2.d1 - v2), w + 1);
        if (v2 < m2.d2) and (v3 >= m2.d2 - v2) and (used[v1, m2.d2, v3 - (m2.d2 - v2)] = 0) then count(v1, m2.d2, v3 - (m2.d2 - v2), w + 1);
        if (v3 >= m3.d1) and (used[v1, v2 + (v3 - m3.d1), m3.d1] = 0) then count(v1, v2 + (v3 - m3.d1), m3.d1, w + 1);
        if (v3 >= m3.d2) and (used[v1, v2 + (v3 - m3.d2), m3.d2] = 0) then count(v1, v2 + (v3 - m3.d2), m3.d2, w + 1);
        if (used[v1, v2 + v3, 0] = 0) then count(v1, v2 + v3, 0, w + 1);
       end;
     {ca}
     if v3 > 0 then
       begin
        if (v1 < m1.d1) and (v3 >= m1.d1 - v1) and (used[m1.d1, v2, v3 - (m1.d1 - v1)] = 0) then count(m1.d1, v2, v3 - (m1.d1 - v1), w + 1);
        if (v1 < m1.d2) and (v3 >= m1.d2 - v1) and (used[m1.d2, v2, v3 - (m1.d2 - v1)] = 0) then count(m1.d2, v2, v3 - (m1.d2 - v1), w + 1);
        if (v3 > m3.d1) and (used[v1 + (v3 - m3.d1), v2, m3.d1] = 0) then count(v1 + (v3 - m3.d1), v2, m3.d1, w + 1);
        if (v3 > m3.d2) and (used[v1 + (v3 - m3.d2), v2, m3.d2] = 0) then count(v1 + (v3 - m3.d2), v2, m3.d2, w + 1);
        if (used[v1 + v3, v2, 0] = 0) then count(v1 + v3, v2, 0, w + 1);
       end;
     {ba}
     if v2 > 0 then
       begin
        if (v1 < m1.d1) and (v2 >= m1.d1 - v1) and (used[m1.d1, v2 - (m1.d1 - v1), v3] = 0) then count(m1.d1, v2 - (m1.d1 - v1), v3, w + 1);
        if (v1 < m1.d2) and (v2 >= m1.d2 - v1) and (used[m1.d2, v2 - (m1.d2 - v1), v3] = 0) then count(m1.d2, v2 - (m1.d2 - v1), v3, w + 1);
        if (v2 > m2.d1) and (used[v1 + (v2 - m2.d1), m2.d1, v3] = 0) then count(v1 + (v2 - m2.d1), m2.d1, v3, w + 1);
        if (v2 > m2.d2) and (used[v1 + (v2 - m2.d2), m2.d2, v3] = 0) then count(v1 + (v2 - m2.d2), m2.d2, v3, w + 1);
        if (used[v1 + v2, 0, v3] = 0) then count(v1 + v2, 0, v3, w + 1);
       end;
    end;
  used[v1, v2, v3] := 0;
 end;





begin
 input;
 count(v, 0, 0, 0);
 writeln(answer);
end.


