//http://acm.cug.edu.cn/JudgeOnline/problem.php?cid=1092&pid=7
//Problem H: 1的最少个数
#include<cmath> #include<cstring> #include<cstdio> #include<iostream> #include<algorithm> using namespace std; int solve(int x) { if(x==0)return 0; int ans=1; int t=1; while(t%x) { ans++; t=(t%x)*10+1; if(ans>100000)return 0; } return ans; } int main() { int n; while(cin>>n) { int ans=solve(n); cout<<ans<<endl; } }