import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int arr [] = new int [6];
        int min = 0 ; 
        for(int i = 0 ; i < 6 ; i++) {
            arr[i] = sc.nextInt();
        }
        int money[] ={1,5,10,50,100,500};
        int sum = sc.nextInt();
        for(int i =5 ; i>=0 ; i--) {
            min += Math.min(sum/money[i], arr[i]);
            sum -= Math.min(sum/money[i], arr[i])*money[i];
        }
        System.out.println(min);
    }
}