n=int(input())

i = 1

print("", end=' ')

while(i<=n):

    x=i

    if x%3 is 0:

        print(i, end=' ')

    elif x%10 is 3:

        print(i, end=' ')

    elif (x/10)%10 is 3:

        print(i, end=' ')

    elif (x/10**2)%10 is 3:

        print(i, end=' ')

    elif (x/10**3)%10 is 3:

        print(i, end=' ')

    elif (x/10**4)%10 is 3:

        print(i, end=' ')

    i = i+1
n=int(input())

i = 1

print("", end=' ')

while(i<=n):

    x=i

    if x%3 is 0:

        print(i, end=' ')

    elif x%10 is 3:

        print(i, end=' ')

    elif (x/10**1)%10 is 3:

        print(i, end=' ')

    elif (x/10**2)%10 is 3:

        print(i, end=' ')

    elif (x/10**3)%10 is 3:

        print(i, end=' ')

    elif (x/10**4)%10 is 3:

        print(i, end=' ')

    i = i+1
n = int(input())
i = 1
print("", end=" ")
while i <= n:
    x = i
    if x % 3 is 0:
        print(i, end=" ")
    elif x % 10 is 3:
        print(i, end=" ")
    elif (x / 10) % 10 is 3:
        print(i, end=" ")
    elif (x / 10**2) % 10 is 3:
        print(i, end=" ")
    elif (x / 10**3) % 10 is 3:
        print(i, end=" ")
    elif (x / 10**4) % 10 is 3:
        print(i, end=" ")
    i = i + 1

n = int(input())
i = 1
print("", end=" ")
while i <= n:
    x = i
    if x % 3 is 0:
        print(i, end=" ")
    elif x % 10 is 3:
        print(i, end=" ")
    elif (x / 10**1) % 10 is 3:
        print(i, end=" ")
    elif (x / 10**2) % 10 is 3:
        print(i, end=" ")
    elif (x / 10**3) % 10 is 3:
        print(i, end=" ")
    elif (x / 10**4) % 10 is 3:
        print(i, end=" ")
    i = i + 1

-    elif (x / 10) % 10 is 3: +    elif (x / 10**1) % 10 is 3: