1. 

/**
* Angewandte Mathematik, SS09, IFB 2C
* ACM Problem 10127 - Ones
* Link: http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=13&page=show_problem&problem=1068
* @author Miesel Christoph
* @author Seilbeck Robert
* @author Wolfram Andre
* @version 1.0 02.06.2009
*
* Status : Accepted
* Runtime: 0.100
*/


import java.util.Scanner;

public class Main
{
public static void main(String... args)
{
Scanner sc = new Scanner(System.in);
while(sc.hasNext())
{
int k = 1;
int n = sc.nextInt();
int r = n==1 ? 0 : 1;
while(r != 0)
{
r = (r*10+1) % n;
k++;
}
System.out.println(k);
}
}
}