/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package lunch;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
//import java.util.Scanner;

/**
 *
 * @author korenciak4
 */
public class Lunch {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) throws IOException {
        //Scanner nacitaj = new Scanner(System.in);
        BufferedReader nacitaj = new BufferedReader(new InputStreamReader(System.in));
        int cena = 0, s = 0, m = 0, d = 0, b = 0;

        int[] sP = null;
        int[] sM = null;
        int[] sD = null;
        int[] sB = null;

        long rieseni = 0;
        String line[];
        
        while (true) {
            line = nacitaj.readLine().split(" ");
            cena = Integer.parseInt(line[0]);
            rieseni = 0;
            s = Integer.parseInt(line[1]);
            m = Integer.parseInt(line[2]);
            d = Integer.parseInt(line[3]);
            b = Integer.parseInt(line[4]);

            if (cena == 0 && s == 0 && m == 0 && d == 0 && b == 0) {
                return;
            }

            sP = new int[s];
            sM = new int[m];
            sD = new int[d];
            sB = new int[b];

            line = nacitaj.readLine().split(" ");
            for (int i = 0; i < s; i++) {
                sP[i] = Integer.parseInt(line[i]);
            }
            line = nacitaj.readLine().split(" ");
            for (int i = 0; i < m; i++) {
                sM[i] = Integer.parseInt(line[i]);
            }
            line = nacitaj.readLine().split(" ");
            for (int i = 0; i < d; i++) {
                sD[i] = Integer.parseInt(line[i]);
            }
            line = nacitaj.readLine().split(" ");
            for (int i = 0; i < b; i++) {
                sB[i] = Integer.parseInt(line[i]);
            }

            Arrays.sort(sB);
            Arrays.sort(sM);
            Arrays.sort(sD);
            Arrays.sort(sP);

            int maxP, maxM, maxD, maxB;
            int c = 0;

            maxP = Arrays.binarySearch(sP, 0, sP.length, cena - c + 1);
            maxP = maxP >= 0 ? maxP : Math.abs(maxP + 1);
            for (int i = 0; i < maxP; ++i) {
                c += sP[i];
                maxM = Arrays.binarySearch(sM, 0, sM.length, cena - c + 1);
                maxM = maxM >= 0 ? maxM : Math.abs(maxM + 1);
                for (int j = 0; j < maxM; j++) {
                    c += sM[j];
                    maxD = Arrays.binarySearch(sD, 0, sD.length, cena - c + 1);
                    maxD = maxD >= 0 ? maxD : Math.abs(maxD + 1);
                    for (int k = 0; k < maxD; k++) {
                        c += sD[k];
                        maxB = Arrays.binarySearch(sB, 0, sB.length, cena - c + 1);
                        maxB = maxB >= 0 ? maxB : Math.abs(maxB + 1);
                        rieseni += maxB;
                        c -= sD[k];
                    }
                    c -= sM[j];
                }
                c -= sP[i];
            }

            System.out.println(rieseni);
        }
    }
}