#include <stdio.h>
#define LENBOUND 10000
#define ARRBOUND 2500 // LENBOUND/4
typedef struct longint {
int length;
int digits[ARRBOUND]; // 0000~9999
} longint;
void ones( longint *pns, int len )
{
int i;
int j;
pns->length = len;
for( i = 0; i < ARRBOUND; i++ )
pns->digits[i] = 0;
j = ARRBOUND - 1;
while( len >= 4 ) {
pns->digits[j] = 1111;
len -= 4;
j--;
}
switch(len) {
case 1:
pns->digits[j] = 1;
break;
case 2:
pns->digits[j] = 11;
break;
case 3:
pns->digits[j] = 111;
break;
}
}
int division( longint *pns, int divisor ) {
int i = ARRBOUND - (pns->length + 3) / 4;
int rem = 0;
for( ; i < ARRBOUND; i++ ) {
pns->digits[i] += (rem * 10000);
rem = pns->digits[i] % divisor;
}
return rem;
}
void main() {
longint ns;
int n;
while( scanf("%d", &n) != EOF ) {
int i;
for( i = 1; i <= LENBOUND; i++ ) {
ones(&ns, i);
if( division(&ns, n) == 0 ) break;
}
if( i <= LENBOUND ) printf("%d\n", i);
}
}