N = [0] + [int(x) for x in list(input())] # 例："1234" → [0, 1, 2, 3, 4]

def dfs(L):
    global N
    if len(L) == len(N):
        if L.count(7) > 0 and L.count(5) > 0 and L.count(3) > 0:
            return 1
        else:
            return 0

    i = len(L) - 1  # Lの右端の桁
    ans = 0
    if L[i] == N[i]:    # Lの0, 1, .., i桁がNの0, 1, ..., i桁と同じ
        next = []
        if i == 0:  # L[i]はダミーの0
            for j in [0, 3, 5, 7]:
                if j <= N[i + 1]:
                    next.append(j)
        else:
            for j in [3, 5, 7]:
                if j <= N[i + 1]:
                    next.append(j)
    elif L[i] == 0:
        next = [0, 3, 5, 7]
    else:
        next = [3, 5, 7]

    for j in next:
        ans += dfs(L + [j])

    return ans

print(dfs([0]))