N = eval(input())



def r(s):

    me = all(('3' in s, '5' in s, '7' in s))

    if len(s) < len(N):

        return r(s+'3') + r(s+'5') + r(s+'7') + me

    elif s<=N:

        return me

    else:

        return 0



print((r('')))

N = eval(input())



def r(s):

    me = '3' in s and '5' in s and '7' in s

    if len(s) < len(N):

        return r(s+'3') + r(s+'5') + r(s+'7') + me

    elif s<=N:

        return me

    else:

        return 0



print((r('')))

N = eval(input())


def r(s):
    me = all(("3" in s, "5" in s, "7" in s))
    if len(s) < len(N):
        return r(s + "3") + r(s + "5") + r(s + "7") + me
    elif s <= N:
        return me
    else:
        return 0


print((r("")))

N = eval(input())


def r(s):
    me = "3" in s and "5" in s and "7" in s
    if len(s) < len(N):
        return r(s + "3") + r(s + "5") + r(s + "7") + me
    elif s <= N:
        return me
    else:
        return 0


print((r("")))

-    me = all(("3" in s, "5" in s, "7" in s)) +    me = "3" in s and "5" in s and "7" in s