n = int(input())
sftnum = [3,5,7]

ans = 0

for i in sftnum:
    for j in sftnum:
        for k in sftnum:
            for ii in sftnum:
                for jj in sftnum:
                    for kk in sftnum:
                        for iii in sftnum:
                            for jjj in sftnum:
                                for kkk in sftnum:
                                    num = i*100000000+j*10000000+k*1000000+ii*100000+jj*10000+kk*1000+iii*100+jjj*10+kkk
                                    if num > n:
                                        break
                                    elif "3" in str(num) and "5" in str(num) and "7" in str(num):
                                        ans = ans +1

for j in sftnum:
    for k in sftnum:
        for ii in sftnum:
            for jj in sftnum:
                for kk in sftnum:
                    for iii in sftnum:
                        for jjj in sftnum:
                            for kkk in sftnum:
                                num = j*10000000+k*1000000+ii*100000+jj*10000+kk*1000+iii*100+jjj*10+kkk
                                if num > n:
                                    break
                                elif "3" in str(num) and "5" in str(num) and "7" in str(num):
                                    ans = ans +1

for k in sftnum:
    for ii in sftnum:
        for jj in sftnum:
            for kk in sftnum:
                for iii in sftnum:
                    for jjj in sftnum:
                        for kkk in sftnum:
                            num = k*1000000+ii*100000+jj*10000+kk*1000+iii*100+jjj*10+kkk
                            if num > n:
                                break
                            elif "3" in str(num) and "5" in str(num) and "7" in str(num):
                                ans = ans +1


for ii in sftnum:
    for jj in sftnum:
        for kk in sftnum:
            for iii in sftnum:
                for jjj in sftnum:
                    for kkk in sftnum:
                        num = ii*100000+jj*10000+kk*1000+iii*100+jjj*10+kkk
                        if num > n:
                            break
                        elif "3" in str(num) and "5" in str(num) and "7" in str(num):
                            ans = ans +1

for jj in sftnum:
    for kk in sftnum:
        for iii in sftnum:
            for jjj in sftnum:
                for kkk in sftnum:
                    num = jj*10000+kk*1000+iii*100+jjj*10+kkk
                    if num > n:
                        break
                    elif "3" in str(num) and "5" in str(num) and "7" in str(num):
                        ans = ans +1

for kk in sftnum:
    for iii in sftnum:
        for jjj in sftnum:
            for kkk in sftnum:
                num = kk*1000+iii*100+jjj*10+kkk
                if num > n:
                    break
                elif "3" in str(num) and "5" in str(num) and "7" in str(num):
                    ans = ans +1

for iii in sftnum:
    for jjj in sftnum:
        for kkk in sftnum:
            num = iii*100+jjj*10+kkk
            if num > n:
                break
            elif "3" in str(num) and "5" in str(num) and "7" in str(num):
                ans = ans +1

print(ans)


Measured memory_bytes: 3192