#include <iostream>
#include <algorithm>
using std::cout;
using std::cin;
using std::min;

//C++ arrays start at 0 (are 0 based.) For convenience we use the coin and pocket arrays from entry 1.
const int coins[] = {0, 1, 5, 10, 25, 100, 200};

//The minimum number of coins the cachier can use to return z cents of change.
//The cachier has an infinite supply of all coins so he can use a greedy algorithm
//to solve his problem (as in Assignment 1)
int cachier(int z) {
  int sol = 0;
  for(int i=6;i>0;i--){
    sol = sol + (z / coins[i]);
    z = z % coins[i];
  }
  return sol;
}

//The coins we have in our pocket.
int pocket[7];

const int maxx = 100000;

//D[i][j] is the minimum number of coins WE would use (from our pocket) to pay exactly
//i cents if we can only use coins coin[0], coin[1], ..., coin[j-1]. I.e. if we don't
//want to trouble the cachier to return any change and we only want to use the j least valuable coins.
//(Notice the similarity to the Knapsack problem)
int D[maxx+201][7];
//We will never need any value of D[i] for i bigger than x+200 as we will see. Why is not imediately obvious.

//Some entries of the D[][] array should be equal to infinity.
//For example if there is no way to pay exactly i cents using the coins we have
//then D[i][j] has to be infinity for every j.
//However, the integer type of most programming languages does not have a special infinity value.
//So we define the following value inf and use it instead of infinity.
//The point being that no solution would ever exchange more than this (large) number of coins.
//In fact as we will see no solution would ever pay more than x + 200 to the cachier
//which will need no more than x+200 coins and the cachier would never have to return change for more than
//200 cents which would need no more than 200 coins (in fact it won't need more than 10 coins). So maxx+401
//would also be sufficient.
const int inf = maxx + 1000;

int main() {
  int x;
  cin >> x;
  for(int i=1;i<=6;i++)
    cin >> pocket[i];

  //Base cases:
  //It takes no coins to pay 0 cents.
  for(int j=0;j<=6;j++)
    D[0][j] = 0;
  
  //It is impossible to pay any nonzero amount if we are not supposed to use any coins!
  for(int i=1;i<=x+200;i++)
    D[i][0] = inf;

  //Recursion:
  for(int i=1;i<=x+200;i++)
    for(int j=1;j<=6;j++){
      //We want to compute D[i][j]. If we are paying for i cents using the j least valuable coins
      //Then we can use the j least valuable coin 0 times, 1 times, ..., pocket[j] times.
      int sol = inf;
      for(int k=0;k<=pocket[j];k++)
	if(i>=k*coins[j])
	  sol = min(sol, D[i-k*coins[j]][j-1] + k);
      D[i][j] = sol;
    }
  //Now that we have computed the D[i][j] values, what we want is the min_z(D[x+z][6] + cachier(z)).
  //This is simply because we have to overpay by _some_ amount z and if we are overpaying by z cents then we need D[x+z][6]
  //coins to pay that much and then the cachier will return us z cent using cachier(z) coins. The only question is in the minimum
  //what is the range of z? clearly z>=0, but what is the upper bound? It is not very hard to see (but it involves a little bit of
  //case analysis) to show that in the optimal solution you do not overpay by more than 200 cents. So we can take the minimum over
  //all 0<=z<=200. That is also the reason we computed D[i][j] for i up to x+200, because that is the range of i's for which we
  //need to know D[i][j].
  int sol = inf;
  for(int z=0;z<=200;z++)
    sol = min(sol, D[x+z][6] + cachier(z));
  cout << sol << '\n';
}

