#include<cstdio>
int p10[]={1,10,100,1000,10000,100000,1000000,10000000};
typedef long long LL;
LL res;
LL atleast(LL a,int b)
{
LL aa=a;
for(;a<b;++res)
a=10*a+9,aa=10*aa;
if(aa<=b)
aa=b;
return aa;
}
struct bignum
{
int m;
int c;
int p;
bignum(const int a): m(a),c(0),p(0){}
void operator ++()
{
++p;
if(c<8 && p>=p10[c])
p-=p10[c],++m;
if(m>1000000000)
m/=10,++c;
}
void next(int a)
{
LL w=atleast(a,m);
if(w>m)
{
if(w>1000000000)
m=w/10,p=0,++c,--res;
else
m=w,p=0;
}
res+=c;
// printf("%d %d %d %lld\n",m,c,p,res);
}
};
int main()
{
int n,b;
scanf("%d%d",&n,&b);
for(bignum x(b);--n;)
{
++x;
scanf("%d",&b);
x.next(b);
}
printf("%lld",res);
return 0;
}