public static void main(String s[]) throws IOException
	{
		int denomination[] = { 1, 7, 10 };
		//CoinChange cc = new CoinChange(14, denomination);
		//System.out.println(cc);
		//for (int i = 0; i <= cc.totalAmount; i++)
			//System.out.print(cc.n[i] + " ");
		
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer tokenizer = new StringTokenizer(br.readLine(), ",");
		ArrayList<Integer> arrIntegers = new ArrayList<>();
		for(;tokenizer.hasMoreTokens();)
		{
			arrIntegers.add(Integer.parseInt(tokenizer.nextToken().trim()));
		}
		int n = Integer.parseInt(br.readLine());
		CoinChange cc = new CoinChange(n, Arrays.copyOf(arrIntegers.toArray(), arrIntegers.size(), Integer[].class));
		System.out.println(cc.getNCoins());
	}