from sys import setrecursionlimit

setrecursionlimit(10**6)
def recur(N_:int,limit:int):
    if N_ > limit:
        return 0
    else:
        N_ *= 10
        return recur(N_ + 3,limit) + recur(N_ + 5,limit) + recur(N_ + 7,limit) + 1


def main():
    N = int(input())
    tmp = [753,735,573,537,375,357]
    ans = 0
    for t in tmp:
        ans += recur(t,N)
    print(ans)
    return   

if __name__ == "__main__":
    main()