#include <bits/stdc++.h>

using namespace std;

template<typename T> ostream& operator<<(ostream &os, const vector<T> &v) { os << '['; string sep; for (const auto &x : v) os << sep << x, sep = ", "; return os << ']'; }
template<typename T, size_t size> ostream& operator<<(ostream &os, const array<T, size> &arr) { os << '{'; string sep; for (const auto &x : arr) os << sep << x, sep = ", "; return os << '}'; }
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '{' << p.first << ", " << p.second << '}'; }
template<typename T> ostream& operator<<(ostream &os, const set<T> &s) { os << '{'; string sep; for (const auto &x : s) os << sep << x, sep = ", "; return os << '}'; }
template<typename A, typename B> ostream& operator<<(ostream &os, const map<A, B> &mp) { os << '['; string sep; for (const auto &x : mp) os << sep << x, sep = ", "; return os << ']'; }
template<typename T> ostream& operator<<(ostream &os, const multiset<T> &s) { os << '{'; string sep; for (const auto &x : s) os << sep << x, sep = ", "; return os << '}'; }

void dbg_out() { cerr << endl; }
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr << ' ' << H; dbg_out(T...); }

#ifndef ONLINE_JUDGE
#define dbg(...) cerr << "[" << #__VA_ARGS__ << "] =", dbg_out(__VA_ARGS__)
#else
#define dbg(...)
#endif

#define int long long
#define mod 1000000007
#define inf 1e18
#define endl '\n'
#define pb push_back
#define ff first
#define ss second
#define lb lower_bound
#define ub upper_bound

#define sz(x) (int)(x).size()
#define sb(x) __builtin_popcountll(x)
#define all(x) x.begin(),x.end()
#define rall(x) (x).rbegin(), (x).rend()

int decimaltoOctal(int deciNum)
{
    int octalNum = 0, countval = 1;
    int dNo = deciNum;
    while (deciNum != 0) {
        int remainder = deciNum % 8;
        octalNum += remainder * countval;
        countval = countval * 10;
        deciNum /= 8;
    }
    return octalNum;
}

bool check(int n) {
    while (n > 0) {
        int digit = n % 10;
        if (digit == 7) return false;
        n /= 10;
    }
    return true;
}

void solve()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    //cout << fixed << setprecision(10);
    int n; cin >> n;
    int ans = 0;
    for (int i = 1; i <= n; i++) {
        if (check(i) && check(decimaltoOctal(i))) {
            ans++;
        }
    }
    dbg(ans);
    // for (int i = 1; i <= n; i++) {
    //     if (check(decimaltoOctal(i))) {
    //         dbg(decimaltoOctal(i));
    //         ans++;
    //     }
    // }
    cout <<  ans << endl;
}

int32_t main()
{
    solve();
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main(){
    ll N;
    cin >> N;
    unordered_set<ll> s;
    for(ll a = 2; a * a <= N; a++){
        ll x = a * a;
        while(x <= N){
            s.insert(x);
            x *= a;
        }
    }
    cout << N - s.size() << endl;
}