n=int(input())
ans=0
a=['3','5','7','0']
cnt=[]
for i1 in range(4):
        for i2 in range(4):
            for i3 in range(4):
                for i4 in range(4):
                    for i5 in range(4):
                        for i6 in range(4):
                            for i7 in range(4):
                                for i8 in range(4):
                                    for i9 in range(4):
                                        for i10 in range(3):
                                            cnt.append(a[i1])
                                            cnt.append(a[i2])
                                            cnt.append(a[i3])
                                            cnt.append(a[i4])
                                            cnt.append(a[i5])
                                            cnt.append(a[i6])
                                            cnt.append(a[i7])
                                            cnt.append(a[i8])
                                            cnt.append(a[i9])
                                            if int(a[i1]+a[i2]+a[i3]+a[i4]+a[i5]+a[i6]+a[i7]+a[i8]+a[i9]+a[i10])<=n and cnt.count('0')<2:
                                                ans+=1
print(ans)