#include<bits/stdc++.h>
using namespace std;
long long head[2000005],tot,dix[2000005],s,vis[2000005];
struct node
{
long long nex,t,d;
}edge[200005];
struct nod
{
long long w,l;
bool operator<(const nod &x) const
{
return x.w<w;
}
};
priority_queue <nod> q;
void add(int x,int y,int z)
{
edge[++tot].t=y;
edge[tot].d=z;
edge[tot].nex=head[x];
head[x]=tot;
}
long long dijie(long long s)
{
memset(dix,0x3f3f3f3f,sizeof(dix));
dix[s]=0;
q.push((nod){0,s});
while(!q.empty())
{
nod u=q.top();
q.pop();
long long l=u.l;
if(vis[l])
continue;
vis[l]=1;
for(int i=head[l];i;i=edge[i].nex)
{
long long t=edge[i].t;
if(dix[t]>dix[l]+edge[i].t)
{
dix[t]=dix[l]+edge[i].d;
if(!vis[t])
q.push((nod){dix[t],t});
}
}
}
cout<<dix[0]+s<<endl;
return dix[0]+s;
}
int main()
{
int n;
long long ans=1e18;
cin>>n;
for(int i=1;i<=n;i++)
for(int j=0;j<=9;j++)
add(i,((i-1)*10+j)%n+1,j);
for(int j=1;j<=9;j++)
add(0,j+1,j);
for(int j=1;j<=9;j++)
ans=min(ans,dijie(j));
cout<<ans;
return 0;
}