#include <math.h>
#include<iostream>
using namespace std;
int master[16777216];
void fac(int num)
{
std::fill_n(master, 0, 0);
master[0] = 1;
int inn = 1;
for (int i = 2; i <= num; i++)
{
int nextround = 0;
for (int i2 = 0; i2 < inn; i2++)
{
int product = master[i2] * i + nextround;
master[i2] = product % 10;
nextround = product * 0.1;
}
while (nextround > 0)
{
master[inn] = nextround % 10;
nextround = nextround * 0.1;
inn++;
}
}
}
int main()
{
int nil, one, two, three, four, five, six, seven, eight, nine;
cin >> nil >> one >> two >> three >> four >> five >> six >> seven >> eight >> nine;
int numz[] = { nil, one, two, three, four, five, six, seven, eight, nine };
int numsum = 0;
for (int i = 0; i <= 10; ++i)
numsum += numz[i];
int wa = 0;
int kick = (int)(0.84 * pow(numsum, 0.89543) + 1);
for (int e = kick; e <= 16777216; ++e)
{
second = 0.0;
for (int i = 0; i < count; ++i)
{
}
for i in range(1, e + 1):
second += log10(i)
second = int(second + 1);
if (second != numsum)
continue
fac(e);
int counters[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
for (int z = 0; z < 30000; ++z)
{
counters[master[z]]++;
}
int z0 = counters[0];
counters[0] = 30000 - z0 - 1;
bool spill = false;
for (int k = 0; k < 10; ++k)
{
spill = counters[k] != numz[k];
if (spill)
break;
}
if (!spill)
{
wa = e;
break;
}
}
cout << wa;
return 0;
}