# ABC114 C - 755

N = int(eval(input()))



def rep(s):

    if int(s) > N:

         return 0

    ret = 1 if all(s.count(c) > 0 for c in '753') else 0 

    for c in '753':

        ret += rep(s + c)

    return ret



print((rep('0')))
# C - 755



def dfs(n,s):

    if int(s)>n:

        return 0

    res=0

    if s.count('7')>0 and s.count('5')>0 and s.count('3')>0:

        res=1

    

    for i in '753':

        res+=dfs(n,s+i)

    return res



n=int(eval(input()))

print((dfs(n,'0')))
# ABC114 C - 755
N = int(eval(input()))


def rep(s):
    if int(s) > N:
        return 0
    ret = 1 if all(s.count(c) > 0 for c in "753") else 0
    for c in "753":
        ret += rep(s + c)
    return ret


print((rep("0")))

# C - 755
def dfs(n, s):
    if int(s) > n:
        return 0
    res = 0
    if s.count("7") > 0 and s.count("5") > 0 and s.count("3") > 0:
        res = 1
    for i in "753":
        res += dfs(n, s + i)
    return res


n = int(eval(input()))
print((dfs(n, "0")))

-# ABC114 C - 755 -N = int(eval(input())) +# C - 755 +def dfs(n, s): +    if int(s) > n: +        return 0 +    res = 0 +    if s.count("7") > 0 and s.count("5") > 0 and s.count("3") > 0: +        res = 1 +    for i in "753": +        res += dfs(n, s + i) +    return res -def rep(s): -    if int(s) > N: -        return 0 -    ret = 1 if all(s.count(c) > 0 for c in "753") else 0 -    for c in "753": -        ret += rep(s + c) -    return ret - - -print((rep("0"))) +n = int(eval(input())) +print((dfs(n, "0")))