#!/usr/bin/env python
# -*- coding: utf-8 -*-

# AtCoder Beginner Contest 114：C - 755
import itertools


def main():
    N = int(raw_input().strip())

    cnt = 0
    seq = ('3', '5', '7')
    for i in range(3, len(str(N))+1):
        for word in itertools.product(seq, repeat=i):
            w = ''.join(word)
            if '3' in w and '5' in w and '7' in w:
                if int(w) <= N:
                    cnt += 1
    print cnt


if __name__ == '__main__':
    main()
