n=int(input())

#print(n)

cnt=0

a=(3,5,7)
b=[]
for i9 in range(len(a)):
    for i8 in range(len(a)):
        for i7 in range(len(a)):
            for i6 in range(len(a)):
                for i5 in range(len(a)):
                    for i4 in range(len(a)):
                        for i3 in range(len(a)):
                            for i2 in range(len(a)):
                                for i in range(len(a)):
                                    x=str(a[i])+str(a[i2])+str(a[i3])+str(a[i4])+str(a[i5])+str(a[i6])+str(a[i7])+str(a[i8])+str(a[i9])
                                    if x.count('3') > 0 and x.count('5') > 0 and x.count('7') > 0:
                                        if int(x) <= n:
                                            cnt+=1
#                                        b.append(x)
#print(len(b9))

for i8 in range(len(a)):
    for i7 in range(len(a)):
        for i6 in range(len(a)):
            for i5 in range(len(a)):
                for i4 in range(len(a)):
                    for i3 in range(len(a)):
                        for i2 in range(len(a)):
                            for i in range(len(a)):
                                x=str(a[i])+str(a[i2])+str(a[i3])+str(a[i4])+str(a[i5])+str(a[i6])+str(a[i7])+str(a[i8])
                                if x.count('3') > 0 and x.count('5') > 0 and x.count('7') > 0:
                                    if int(x) <= n:
                                        cnt+=1
#                                        b.append(x)
#print(len(b8))

for i7 in range(len(a)):
    for i6 in range(len(a)):
        for i5 in range(len(a)):
            for i4 in range(len(a)):
                for i3 in range(len(a)):
                    for i2 in range(len(a)):
                        for i in range(len(a)):
                            x=str(a[i])+str(a[i2])+str(a[i3])+str(a[i4])+str(a[i5])+str(a[i6])+str(a[i7])
                            if x.count('3') > 0 and x.count('5') > 0 and x.count('7') > 0:
                                if int(x) <= n:
                                    cnt+=1
#                                        b.append(x)

#print(len(b7))

for i6 in range(len(a)):
    for i5 in range(len(a)):
        for i4 in range(len(a)):
            for i3 in range(len(a)):
                for i2 in range(len(a)):
                    for i in range(len(a)):
                        x=str(a[i])+str(a[i2])+str(a[i3])+str(a[i4])+str(a[i5])+str(a[i6])
                        if x.count('3') > 0 and x.count('5') > 0 and x.count('7') > 0:
                            if int(x) <= n:
                                cnt+=1
#                                        b.append(x)

#print(len(b6))


for i5 in range(len(a)):
    for i4 in range(len(a)):
        for i3 in range(len(a)):
            for i2 in range(len(a)):
                for i in range(len(a)):
                    x=str(a[i])+str(a[i2])+str(a[i3])+str(a[i4])+str(a[i5])
                    if x.count('3') > 0 and x.count('5') > 0 and x.count('7') > 0:
                        if int(x) <= n:
                            cnt+=1
#                                        b.append(x)

#print(len(b5))
      
for i4 in range(len(a)):
    for i3 in range(len(a)):
        for i2 in range(len(a)):
            for i in range(len(a)):
                x=str(a[i])+str(a[i2])+str(a[i3])+str(a[i4])
                if x.count('3') > 0 and x.count('5') > 0 and x.count('7') > 0:
                    if int(x) <= n:
                        cnt+=1
#                                        b.append(x)

#print(len(b4))

for i3 in range(len(a)):
    for i2 in range(len(a)):
        for i in range(len(a)):
            x=str(a[i])+str(a[i2])+str(a[i3])
            if x.count('3') > 0 and x.count('5') > 0 and x.count('7') > 0:
                if int(x) <= n:
                    cnt+=1
#                   b.append(x)
print(cnt)


Measured memory_bytes: 3320