/*
TASK:water
LANG:C++
*/
#include <stdio.h>
#include <queue>
#define FOR(i,n) for(int i=0;i<n;i++)
#define debi(x) printf("%d\n",x);

struct state {
       int a,b,c,k;
       state() {}
       state(int _a,int _b,int _c,int _k) {
                 a = _a;
                 b = _b;
                 c = _c;
                 k = _k;
       }
};

int v,maxk;
int a1,a2,b1,b2,c1,c2;

void init() {
     scanf("%d %d",&v,&maxk);
     scanf("%d %d %d %d %d %d",&a1,&a2,&b1,&b2,&c1,&c2);
     if(a1 > a2) {
           int swap = a1;
           a1 = a2;
           a2 = swap;
     }
     if(b1 > b2) {
           int swap = b1;
           b1 = b2;
           b2 = swap;
     }
     if(c1 > c2) {
           int swap = c1;
           c1 = c2;
           c2 = swap;
     }
}

bool final(state s) {
     return (s.a==1 || s.b==1 || s.c==1);
}

void solve() {
     int res(0);
     std::queue<state> q;
     q.push(state(v,0,0,0));
     
     while(!q.empty()) {
          state f = q.front();
          q.pop();
//          printf("%d %d %d %d\n",f.a,f.b,f.c,f.k);
          if(final(f)) {
            //printf("%d %d %d %d\n",f.a,f.b,f.c,f.k);
            res++;
            continue;
          }
          if(f.k==maxk) continue;
          
          // A
          if(f.a) {
             // b
             if(f.a + f.b <= v) {
                    state nst = f;
                    nst.b += nst.a;
                    nst.a = 0;
                    nst.k++;
                    q.push(nst);
             }
             int x1,x2;
             x1 = f.a - a1;
             x2 = f.a - a2;
             if(x1 && f.b + x1 <= v) {
                    state nst = f;
                    nst.b += x1;
                    nst.a = a1;
                    nst.k++;
                    q.push(nst);
             }
             if(x2 && f.b + x2 <= v) {
                   state nst = f;
                   nst.b += x2;
                   nst.a = a2;
                   nst.k++;
                   q.push(nst);
             }
             
             x1 = b1 - f.b;
             x2 = b2 - f.b;
             if(x1 && f.a>x1) { // a>= ???
                   state nst = f;
                   nst.b += x1;
                   nst.a -= x1;
                   nst.k++;
                   q.push(nst);
             }
             if(x2 && f.a>x2) {
                   state nst = f;
                   nst.b += x2;
                   nst.a -= x2;
                   nst.k++;
                   q.push(nst);
             }
             
             //c
             
             if(f.a + f.c <= v) {
                    state nst = f;
                    nst.c += nst.a;
                    nst.a = 0;
                    nst.k++;
                    q.push(nst);
             }
             x1 = f.a - a1;
             x2 = f.a - a2;
             if(x1 && f.c + x1 <= v) {
                    state nst = f;
                    nst.c += x1;
                    nst.a = a1;
                    nst.k++;
                    q.push(nst);
             }
             if(x2 && f.c + x2 <= v) {
                   state nst = f;
                   nst.c += x2;
                   nst.a = a2;
                   nst.k++;
                   q.push(nst);
             }
             
             x1 = c1 - f.c;
             x2 = c2 - f.c;
             if(x1 && f.a>x1) { // a>= ???
                   state nst = f;
                   nst.c += x1;
                   nst.a -= x1;
                   nst.k++;
                   q.push(nst);
             }
             if(x2 && f.a>x2) {
                   state nst = f;
                   nst.c += x2;
                   nst.a -= x2;
                   nst.k++;
                   q.push(nst);
             }
          }
          if(f.b) {
                  // a    
             if(f.a + f.b <= v) {
                    state nst = f;
                    nst.a += nst.b;
                    nst.b = 0;
                    nst.k++;
                    q.push(nst);
             }
             int x1,x2;
             x1 = f.b - b1;
             x2 = f.b - b2;
             if(x1 && f.a + x1 <= v) {
                    state nst = f;
                    nst.a += x1;
                    nst.b = b1;
                    nst.k++;
                    q.push(nst);
             }
             if(x2 && f.a + x2 <= v) {
                   state nst = f;
                   nst.a += x2;
                   nst.b = b2;
                   nst.k++;
                   q.push(nst);
             }
             
             x1 = a1 - f.a;
             x2 = a2 - f.a;
             if(x1 && f.b>x1) { // a>= ???
                   state nst = f;
                   nst.a += x1;
                   nst.b -= x1;
                   nst.k++;
                   q.push(nst);
             }
             if(x2 && f.b>x2) {
                   state nst = f;
                   nst.a += x2;
                   nst.b -= x2;
                   nst.k++;
                   q.push(nst);
             }
             
             // c
             if(f.c + f.b <= v) {
                    state nst = f;
                    nst.c += nst.b;
                    nst.b = 0;
                    nst.k++;
                    q.push(nst);
             }
             x1 = f.b - b1;
             x2 = f.b - b2;
             if(x1 && f.c + x1 <= v) {
                    state nst = f;
                    nst.c += x1;
                    nst.b = b1;
                    nst.k++;
                    q.push(nst);
             }
             if(x2 && f.c + x2 <= v) {
                   state nst = f;
                   nst.c += x2;
                   nst.b = b2;
                   nst.k++;
                   q.push(nst);
             }
             
             x1 = c1 - f.c;
             x2 = c2 - f.c;
             if(x1 && f.b>x1) { // a>= ???
                   state nst = f;
                   nst.c += x1;
                   nst.b -= x1;
                   nst.k++;
                   q.push(nst);
             }
             if(x2 && f.b>x2) {
                   state nst = f;
                   nst.c += x2;
                   nst.b -= x2;
                   nst.k++;
                   q.push(nst);
             }
          }
          if(f.c) {
              // a
              if(f.c + f.a <= v) {
                    state nst = f;
                    nst.a += nst.c;
                    nst.c = 0;
                    nst.k++;
                    q.push(nst);
             }
             int x1,x2;
             x1 = f.c - c1;
             x2 = f.c - c2;
             if(x1 && f.a + x1 <= v) {
                    state nst = f;
                    nst.a += x1;
                    nst.c = c1;
                    nst.k++;
                    q.push(nst);
             }
             if(x2 && f.a + x2 <= v) {
                   state nst = f;
                   nst.a += x2;
                   nst.c = c2;
                   nst.k++;
                   q.push(nst);
             }
             
             x1 = a1 - f.a;
             x2 = a2 - f.a;
             if(x1 && f.c>x1) { // a>= ???
                   state nst = f;
                   nst.a += x1;
                   nst.c -= x1;
                   nst.k++;
                   q.push(nst);
             }
             if(x2 && f.c>x2) {
                   state nst = f;
                   nst.a += x2;
                   nst.c -= x2;
                   nst.k++;
                   q.push(nst);
             }
             
             // b
             if(f.c + f.b <= v) {
                    state nst = f;
                    nst.b += nst.c;
                    nst.c = 0;
                    nst.k++;
                    q.push(nst);
             }
             x1 = f.c - c1;
             x2 = f.c - c2;
             if(x1 && f.b + x1 <= v) {
                    state nst = f;
                    nst.b += x1;
                    nst.c = c1;
                    nst.k++;
                    q.push(nst);
             }
             if(x2 && f.b + x2 <= v) {
                   state nst = f;
                   nst.b += x2;
                   nst.c = c2;
                   nst.k++;
                   q.push(nst);
             }
             
             x1 = b1 - f.b;
             x2 = b2 - f.b;
             if(x1 && f.c>x1) { // a>= ???
                   state nst = f;
                   nst.b += x1;
                   nst.c -= x1;
                   nst.k++;
                   q.push(nst);
             }
             if(x2 && f.c>x2) {
                   state nst = f;
                   nst.b += x2;
                   nst.c -= x2;
                   nst.k++;
                   q.push(nst);
             }
          }
     }
     
     printf("%d\n",res);
//     scanf("%d",&res);
}

int main() {
    init();
    solve();
    return 0;
}
