#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cstdint>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cmath>
#include <cstdlib>
#include <sstream>
#include <functional>

#include <boost/range/irange.hpp>
using boost::irange;

#include <boost/utility/string_ref.hpp>
using string_view = boost::string_ref;

using namespace std;

template<class T, size_t N, class F>
struct compare_n
{
    F f;
    bool operator() (const T& t1, const T& t2)
    {
        return f(get<N>(t1), get<N>(t2));
    }
};
 
template<size_t N, class T>
auto make_less_n(const T&)
{
    using t = typename T::value_type;
    using less = std::less<typename tuple_element<N, t>::type>;
    return compare_n<t, N, less>();
}


template<class T>
T digit(T x)
{
    return static_cast<T>(floor(log10(x)+1));
}

int64_t ipow(int64_t x, int64_t y)
{
    return static_cast<int64_t>(pow(x, y));
}

int64_t number_of_753_d(int64_t digits)
{
    if(digits <= 2) return 0;
    return ipow(3L, digits) - ((1L << digits)-2)*3 - 3;
}

template<class T>
T msd(T x)
{
    while(x > 10) x /= 10;
    return x;
}

int64_t remove_msd(int64_t x)
{
    return x - msd(x) * ipow(10L, digit(x)-1);
}

int64_t number_of_753(int64_t upper_limit)
{
    const auto smaller_digits_n_f = [=](){ return number_of_753_d(digit(upper_limit)-1); };

    switch(msd(upper_limit))
    {
        case 1: case 2: default:
            return smaller_digits_n_f();
        case 3:
            return smaller_digits_n_f() + ((1L << (digit(upper_limit)-1))-2)*3;
        case 4:
            return smaller_digits_n_f() * 2;
        case 5:
            return smaller_digits_n_f() * 2 + ((1L << (digit(upper_limit)-1))-2)*3;
        case 6:
            return smaller_digits_n_f() * 3;
        case 7:
            return smaller_digits_n_f() * 4 + ((1L << (digit(upper_limit)-1))-2)*3;
        case 8: case 9:
            return number_of_753_d(digit(upper_limit));
    }
}

/*
333
337
373
733
773
737
377
777
*/

void foreach_753_like_n(int64_t digit, function<void(int64_t)> f)
{
    if(digit > 1)
    {
        auto scale = ipow(10L, digit-1);
        foreach_753_like_n(digit - 1, [=](int64_t x){
            f(x);
            for(auto i : {3, 5, 7})
            {
                f(i * scale + x);
            }
        });
    }
    else
    {
        for(auto i : {3, 5, 7})
        {
            f(i);
        }    
    }
}

void foreach_753_n(int64_t x, function<void(int64_t)> f)
{
    foreach_753_like_n(digit(x), [=](int64_t cand)
    {
        if(cand <= x)
        {
            int counts[4] = {0,0,0,0};
            for(int64_t c = cand; c != 0; c /= 10)
            {
                switch(c%10){
                    case 3: counts[0]++; break;
                    case 5: counts[1]++; break;
                    case 7: counts[2]++; break;
                    default:  counts[3]++; break;
                }
            }
            if(counts[0] > 0 && counts[1] > 0 && counts[2] > 0 && counts[3] == 0)
            {
                f(cand);
            }
        }
    });
}

int main()
{
    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    int64_t n;
    cin >> n;
    
    int64_t count = 0;
    
    foreach_753_n(n, [&](int64_t x){
        count++;
        //cout << x << endl;
    });
    
    cout << count << endl;

    return 0;
}



Measured memory_bytes: 640