import sys
from collections import defaultdict, Counter, deque
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter
from bisect import bisect_left, bisect_right, bisect
from heapq import heappop, heappush
from fractions import gcd
from math import ceil, floor, sqrt, cos, sin, pi
from copy import deepcopy

# If you use recursive call, uncomment this code
#sys.setrecursionlimit(10**6)

def main():
    N = input()
    NN = int(N)
    l = len(N)

    count = 0

    for i in range(1,l):
        count += 3**i 
        count -= 2**i * 3
        count += 3

    candidates = product(["3","5","7"], repeat=l)
    candidates = map(lambda x: "".join(x), candidates)
    candidates = filter(lambda x: len(set(x)) == 3, candidates)
    candidates = filter(lambda x: x < N, candidates)
    candidates = list(candidates)

    print(count + len(candidates))

if __name__ == '__main__':
    main()