Charles is a fan of auto racing and has decided to build his own collection of car models. In the shop, models are sold in identical sealed boxes. Each box contains the parts for exactly one model together with a set of stickers showing digits. Every box contains the same set of stickers.
Charles labels his models with consecutive integers starting from 1. For example, to label model number 2070 he needs four stickers: one 2, two 0s, and one 7.
He assembles the models one at a time. To build the next model he opens one new box, assembles the model, and then labels it with its number using stickers. He may use stickers from the box he has just opened and from any box he opened earlier, but he is not allowed to open an extra box just to obtain stickers he is missing. As soon as he cannot fully label the current model, he stops.
Given the sticker set contained in every box, determine how many models Charles can label in this way.
Ten single-digit integers are given on one line:
$$i_0\ i_1\ i_2\ i_3\ i_4\ i_5\ i_6\ i_7\ i_8\ i_9$$
where $i_j$ is the number of stickers showing digit $j$ ($0 \le j \le 9$) in each box. Consecutive values are separated by a single space, and each $i_j$ is a single digit ($0 \le i_j \le 9$).
Print one integer: the number of models Charles can label.