# include <bits/stdc++.h>
# define rep(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
# define reps(i, n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
# define rrep(i, n) for(int i=((int)(n)-1); i>=0; --i)
# define rreps(i, n) for(int i=((int)(n)); i>0; --i)
# define ALL(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size())
# define pb push_back
# define optimize_cin() cin.tie(0); ios::sync_with_stdio(false)
using namespace std;
using lint = long long;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int main()
{
    int N;
    cin >> N;

    int cnt = 1;
    char tmp[10];
    bool can;
    bool a, b, c;

    
    if (N < 357)
    {
        cout << 0 << "\n";
        return 0;
    }

    /*
    vector<int> v;
    vector<int> w;
    while (N != 0)
    {
        v.pb(N % 10);
        N /= 10;
    }
    rep (i + 4, SZ(v))
    {
        if (v[i] == 3)
        {
            w.pb(1);
        }
        else if (v[i] == 5)
        {
            w.pb(2);
        }
        else if (v[i] == 7)
        {
            w.pb(3);
        }
    }

    rep (i, w.size())
    {

    }
    */


    
    for (int i = 358; i < N; ++i)
    {
        int buf = i;
        int digit = 0;
        can = true;
        a = b = c = false;
        while (buf != 0)
        {
            int r = buf % 10;
            if (r == 0 ||
                r == 1 || 
                r == 2 || 
                r == 4 || 
                r == 6 || 
                r == 8 || 
                r == 9 
                )
            {
                can = false;
                break;
            }
            else
            {
                if (r == 3)
                {
                    a = true;
                }
                else if (r == 5)
                {
                    b = true;
                }
                else if (r == 7)
                {
                    c = true;
                }
            }
            buf /= 10;
            digit++;
        }
        if (can & a & b & c)
        {
            cnt++;
        }
        if (can & !a & !b)
        {
            i = atoi("7" + to_string(i));
        }
    }
    
    cout << cnt << "\n";

    return 0;
}
