# ABC114



N = int(eval(input()))

def dfs(num):

    if num > N:

        return 0

    flag = True

    for s in "357":

        if str(num).count(s) >= 1:

            pass

        else:

            flag = False

    ret = 1 if flag else 0



    for c in [3, 5, 7]:

        ret += dfs(num * 10 + c)

    return ret

ans = dfs(0)

print(ans)
# ABC114



N = int(eval(input()))

def dfs(num, use):

    if num > N:

        return 0

    cnt = 1 if use == 0b111 else 0

    cnt += dfs(num*10 + 3, use | 0b001)

    cnt += dfs(num*10 + 5, use | 0b010)

    cnt += dfs(num*10 + 7, use | 0b100)

    return cnt

ans = dfs(0, 0)

print(ans)
# ABC114
N = int(eval(input()))


def dfs(num):
    if num > N:
        return 0
    flag = True
    for s in "357":
        if str(num).count(s) >= 1:
            pass
        else:
            flag = False
    ret = 1 if flag else 0
    for c in [3, 5, 7]:
        ret += dfs(num * 10 + c)
    return ret


ans = dfs(0)
print(ans)

# ABC114
N = int(eval(input()))


def dfs(num, use):
    if num > N:
        return 0
    cnt = 1 if use == 0b111 else 0
    cnt += dfs(num * 10 + 3, use | 0b001)
    cnt += dfs(num * 10 + 5, use | 0b010)
    cnt += dfs(num * 10 + 7, use | 0b100)
    return cnt


ans = dfs(0, 0)
print(ans)

-def dfs(num): +def dfs(num, use): -    flag = True -    for s in "357": -        if str(num).count(s) >= 1: -            pass -        else: -            flag = False -    ret = 1 if flag else 0 -    for c in [3, 5, 7]: -        ret += dfs(num * 10 + c) -    return ret +    cnt = 1 if use == 0b111 else 0 +    cnt += dfs(num * 10 + 3, use | 0b001) +    cnt += dfs(num * 10 + 5, use | 0b010) +    cnt += dfs(num * 10 + 7, use | 0b100) +    return cnt -ans = dfs(0) +ans = dfs(0, 0)