#include "bits/stdc++.h"
 
typedef long long ll;
#define int ll
#define fi first
#define se second
#define SORT(a) sort(a.begin(),a.end())
#define rep(i,n) for(int i = 0;i < (n) ; i++) 
#define REP(i,n) for(int i = 0;i < (n) ; i++) 
#define MP(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define INF LLONG_MAX/2

using namespace std;

int MOD = 1000000007;

signed main(){
    int n;
    cin >> n;
    int ans = 0;

    int m[] = {3,5,7};
    int x1,x2;

    rep(a1,3){
    rep(a2,3){
    rep(a3,3){
         x1 = m[a1] * m[a2]* m[a3];
         x2 = m[a1] + m[a2]*10 + m[a3]*100;
        if(x1%3 == 0 && x1%5 == 0 && x1%7 == 0 && x2 <= n)ans++;
    }}}

    rep(a1,3){
    rep(a2,3){
    rep(a3,3){
    rep(a4,3){
        x1 = m[a1] * m[a2]* m[a3]*m[a4];
        x2 = m[a1] + m[a2]*10 + m[a3]*100+ m[a4]*1000;
        if(x1%3 == 0 && x1%5 == 0 && x1%7 == 0 && x2 <= n)ans++;
    }}}}

    rep(a1,3){
    rep(a2,3){
    rep(a3,3){
    rep(a4,3){
    rep(a5,3){
        x1 = m[a1] * m[a2]* m[a3]*m[a4]*m[a5];
        x2 = m[a1] + m[a2]*10 + m[a3]*100+ m[a4]*1000+ m[a5]*10000 ;
        if(x1%3 == 0 && x1%5 == 0 && x1%7 == 0 && x2 <= n)ans++;
    }}}}}

    rep(a1,3){
    rep(a2,3){
    rep(a3,3){
    rep(a4,3){
    rep(a5,3){
    rep(a6,3){
        x1 = m[a1] * m[a2]* m[a3]*m[a4]*m[a5]*m[a6];
        x2 = m[a1] + m[a2]*10 + m[a3]*100+ m[a4]*1000+ m[a5]*10000 + m[a6]*100000 ;
        if(x1%3 == 0 && x1%5 == 0 && x1%7 == 0 && x2 <= n)ans++;
    }}}}}}

    rep(a1,3){
    rep(a2,3){
    rep(a3,3){
    rep(a4,3){
    rep(a5,3){
    rep(a6,3){    
    rep(a7,3){
        x1 = m[a1] * m[a2]* m[a3]*m[a4]*m[a5]*m[a6]*m[a7];
        x2 = m[a1] + m[a2]*10 + m[a3]*100+ m[a4]*1000+ m[a5]*10000 + m[a6]*100000 + + m[a7]*1000000;
        if(x1%3 == 0 && x1%5 == 0 && x1%7 == 0 && x2 <= n)ans++;
    }}}}}}}

    rep(a1,3){
    rep(a2,3){
    rep(a3,3){
    rep(a4,3){
    rep(a5,3){
    rep(a6,3){    
    rep(a7,3){
    rep(a8,3){
        x1 = m[a1] * m[a2]* m[a3]*m[a4]*m[a5]*m[a6]*m[a7]*m[a8];
        x2 = m[a1] + m[a2]*10 + m[a3]*100 + m[a4]*1000 + m[a5]*10000
                + m[a6]*100000 + m[a7]*1000000 + m[a8]*10000000;
        if(x1%3 == 0 && x1%5 == 0 && x1%7 == 0 && x2 <= n)ans++;
    }}}}}}}}

    rep(a1,3){
    rep(a2,3){
    rep(a3,3){
    rep(a4,3){
    rep(a5,3){
    rep(a6,3){    
    rep(a7,3){
    rep(a8,3){
    rep(a9,3){
        x1 = m[a1] * m[a2]* m[a3]*m[a4]*m[a5]*m[a6]*m[a7]*m[a8]*m[a9];
        x2 = m[a1] + m[a2]*10 + m[a3]*100 + m[a4]*1000 + m[a5]*10000
                + m[a6]*100000 + m[a7]*1000000 + m[a8]*10000000 + m[a9]*100000000;
        if(x1%3 == 0 && x1%5 == 0 && x1%7 == 0 && x2 <= n)ans++;
    }}}}}}}}}

    // rep(a1,3){
    // rep(a2,3){
    // rep(a3,3){
    // rep(a4,3){
    // rep(a5,3){
    // rep(a6,3){    
    // rep(a7,3){
    // rep(a8,3){
    // rep(a9,3){  
    //     int x = m[a1] + m[a2]*10 + m[a3]*100 + m[a4]*1000 + m[a5]*10000
    //             + m[a6]*100000 + m[a7]*1000000 + m[a8]*10000000 + m[a9]*100000000;
    //     //cerr << x << " ";

    //     int x1 = m[a1] * m[a2]* m[a3];
    //     int x2 = m[a1] + m[a2]*10 + m[a3]*100;
    //     if(x1%3 == 0 && x1%5 == 0 && x1%7 == 0 && x2 <= n)ans++;

    //     x1 = m[a1] * m[a2]* m[a3]*m[a4];
    //     x2 = m[a1] + m[a2]*10 + m[a3]*100+ m[a4]*1000;
    //     if(x1%3 == 0 && x1%5 == 0 && x1%7 == 0 && x2 <= n)ans++;

    //     x1 = m[a1] * m[a2]* m[a3]*m[a4]*m[a5];
    //     x2 = m[a1] + m[a2]*10 + m[a3]*100+ m[a4]*1000+ m[a5]*10000 ;
    //     if(x1%3 == 0 && x1%5 == 0 && x1%7 == 0 && x2 <= n)ans++;

    //     x1 = m[a1] * m[a2]* m[a3]*m[a4]*m[a5]*m[a6];
    //     x2 = m[a1] + m[a2]*10 + m[a3]*100+ m[a4]*1000+ m[a5]*10000 + m[a6]*100000 ;
    //     if(x1%3 == 0 && x1%5 == 0 && x1%7 == 0 && x2 <= n)ans++;

    //     x1 = m[a1] * m[a2]* m[a3]*m[a4]*m[a5]*m[a6]*m[a7];
    //     x2 = m[a1] + m[a2]*10 + m[a3]*100+ m[a4]*1000+ m[a5]*10000 + m[a6]*100000 + + m[a7]*1000000;
    //     if(x1%3 == 0 && x1%5 == 0 && x1%7 == 0 && x2 <= n)ans++;

    //     x1 = m[a1] * m[a2]* m[a3]*m[a4]*m[a5]*m[a6]*m[a7]*m[a8];
    //     x2 = x - m[a9]*100000000;
    //     if(x1%3 == 0 && x1%5 == 0 && x1%7 == 0 && x2 <= n)ans++;

    //     x1 = m[a1] * m[a2]* m[a3]*m[a4]*m[a5]*m[a6]*m[a7]*m[a8]*m[a9];
    //     x2 = x;
    //     if(x1%3 == 0 && x1%5 == 0 && x1%7 == 0 && x2 <= n)ans++;

    //     // cout << x << " " << x1 << " " << x2 << endl;
    // }
    // }
    // }
    // }
    // }
    // }
    // }
    // }
    // }

    cout << ans << endl;

    return 0;
}
// g++ -std=c++14 code1.cpp
// rm -r -f test;oj dl 

Measured memory_bytes: 256