program easy;

const value: array[1..10] of integer = (1,2,5,10,20,50,100,200,500,1000);
var coins: array[1..10] of integer;
    i, price, result: integer;

function pay(v: integer): integer;
  var i, m, unsuccess: integer;
  begin
    unsuccess := 0;
    m := 0;
    i := 10;
    while ((v > 0) and (unsuccess<10)) do begin
      if ((value[i] <= v) and (coins[i] > 0)) then begin
        v := v - value[i];
        coins[i] := coins[i] - 1;
        m := m + 1;
        unsuccess := 0;
      end else
	unsuccess := unsuccess + 1;
      i := (i+8) mod 10 + 1;
    end;

    if (v > 0) then m := -1;
    pay := m;
  end;

begin
  for i := 1 to 10 do read(coins[i]);
  read(price);

  result := pay(price);
  writeln(result);
end.


#include <stdio.h>

int coins[10];
int value[10] = {1,2,5,10,20,50,100,200,500,1000};

int pay(int v) {
  int i, m, unsuccess;

  unsuccess = 0;
  m = 0;
  i = 9;
  while ((v > 0) && (unsuccess<10)) {
    if ((value[i] <= v) && (coins[i] > 0)) {
      v -= value[i];
      coins[i]--;
      m++;
      unsuccess = 0;
    } else
      unsuccess++;
    i = (i+9) % 10;
  }

  if (v > 0) m = -1;
  return m;
}

int main() {
  int i, price, result;

  for (i = 0; i < 10; i++) scanf("%i", &coins[i]);
  scanf("%i", &price);

  result = pay(price);
  printf("%d\n", result);
  return 0;
}
