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 payClassic(v: integer): integer;
  var i, m, used: integer;
  begin
    used := 0;
    for i := 10 downto 1 do begin
      if (value[i] <= v) then begin
        m := v div value[i];
        if (m > coins[i]) then m := coins[i];
        used := used + m;
        v := v - m * value[i];
      end;
    end;

    if (v > 0) then used := -1;
    payClassic := used;
  end;

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

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


#include <stdio.h>

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

int payClassic(int v) {
  int i, m, used;

  used = 0;
  for (i = 9; i >= 0; i--) {
      if (value[i] <= v) {
          m = v / value[i];
          if (m > coins[i]) m = coins[i];
          used += m;
          v -= m * value[i];
      }
  }

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

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

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

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