from fractions import gcd
from functools import reduce
from collections import deque
# from math import factorial
import itertools
import collections
import math
import sys
sys.setrecursionlimit(2000000)
# import statistics
# import numpy as np
# n = int(input())
# a, b, c, k = list(map(int, input().split()))
# a = list(map(int, input().split()))
# abc = [int(input()) for i in range(5)]
n = int(input())
# n, m = list(map(int, input().split()))
# n, m = list(map(int, input().split()))
# x = list(map(int, input().split()))
# abc = [int(input()) for i in range(5)]
# n = int(input())
# n, m = list(map(int, input().split()))
if n < 357:
    print(0)
else:
    l = len(str(n))
    num = [3, 5, 7]*l
    data = []
    for j in range(3, l+1):
        for v in itertools.permutations(num, j):
            a = ""
            for i in range(j):
                a += str(v[i])

            if int(a) <= n:
                if "3" in a and "5" in a and "7" in a:
                    data.append(a)
            # print(v)
    # print(data)
    ans = set(list(data))
    print(len(ans))
  