import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.StringTokenizer;
public class C430 {
static int[] array;
static int digits = 0;
static long currentN = 2;
static boolean solved = false;
public static void main(String[] args) {
FastReader reader = new FastReader();
PrintWriter writer = new PrintWriter(new OutputStreamWriter(System.out));
array = new int[10];
// 100000
// 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000
for (int i = 0; i < array.length; i++) {
int num = reader.nextInt();
array[i] = num;
digits += num;
}
reader.close();
findLowest();
if (digits < 1000) {
while (!solved) {
solve();
}
writer.println(currentN);
} else {
writer.println(currentN);
}
writer.flush();
writer.close();
}
static void findLowest() {
long difference = digits - countDigits(currentN);
if (difference == -1) {
currentN = 0;
return;
}
if (difference > 0) {
currentN += difference >= 1000 ? 1000 : 1;
findLowest();
}
}
static long countDigits(long n) {
double total = 0;
for (long i = 2; i <= n; i++)
total += Math.log10(i);
return (int) (Math.floor(total)) + 1;
}
static void solve() {
for (int i = 0; i < array.length; i++) {
long count = count(factorial(currentN).toString(), (char) (i + '0'));
if (count != array[i]) {
currentN += 1;
return;
}
}
solved = true;
}
static int count(String s, char c) {
int count = 0;
for (int i = 0; i < s.length(); i++) {
if (s.charAt(i) == c)
count++;
}
return count;
}
static BigInteger factorial(long number) {
BigInteger factorial = BigInteger.ONE;
for (long i = number; i > 0; i--) {
factorial = factorial.multiply(BigInteger.valueOf(i));
}
return factorial;
}
static class FastReader {
private BufferedReader br;
private StringTokenizer st;
public FastReader() {
br = new BufferedReader(new InputStreamReader(System.in));
}
void close() {
try {
br.close();
} catch (IOException e) {
e.printStackTrace();
}
st = null;
br = null;
}
String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
String nextLine() {
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
int nextInt() {
return Integer.parseInt(next());
}
BigInteger nextBigInteger() {
return new BigInteger(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
long nextLong() {
return Long.parseLong(next());
}
}
}