#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b, c, d, e, f, g, h, i, j, s, m, dig, digf;
double x;
m = 0;
dig = 1;
digf = 1;
x = 1;
cin >> a >> b >> c >> d >> e >> f >> g >> h >> i >> j;
s = a+b+c+d+e+f+g+h+i+j;
if (s <= 6) {
if (c == 1 and a == 0 and e == 0) {
cout << "2";
}
if (g == 1) {
cout << "3";
}
if (s == 2) {
cout << "4";
}
if (a == 1 and b == 1) {
cout << "5";
}
if (a == 1 and b == 0) {
cout << "6";
}
}
else {
for (int z = 1; z <= 30000; z++) {
x = x*z;
while (x > 1000000) {
if (x > 1000000) {
m = m+1;
x = x/1000000;
}
}
for (int y = 0; y <= 12; y++) {
if (x => pow(10,y) and x < pow(10,(y+1))) {
dig = y+1;
}
}
digf = 6*m+dig;
if (digf == s) {
cout << z;
break;
}
}
}
}