int main(int argc, char const* argv[])
{
int n;
while (~scanf("%d",&n)) {
string ans;
int remain = 0;
if(n == 0)
printf("0\n");
else{
do{
remain = (remain*10+1)%n;
ans = ans+"1";
}while(remain != 0);
printf("%d\n",ans.length());
}
}
return 0;
}