#include<iostream>
#include<vector>
#include<math.h>
#include<algorithm>
using namespace std;
main()
{
long long int n,i,j;
vector<long long int>v;
 cin>>n;
  for(i=1;i<=sqrt(n);i++)
      {
        if(n%i==0 && i*i!=n)
        {
         v.push_back(i);
          v.push_back(n/i);
        }        
        else if(i*i==n)
        {
          v.push_back(i);
          
        }
      }
      sort(v.begin(),v.end());
      for(i=0;i<v.size();i++)
      {

      cout<<v[i]<<endl;
      
      }      
  










}
#include<iostream>
#include<bits/stdc++.h>
#include <cmath>
#include <cstdio>
#include<climits>
#include <algorithm>
using namespace std;

const long long M = 1e9 + 7;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pi;
#define IOS ios::sync_with_stdio(0); cin.tie(0);
#define endl "\n"
#define pb push_back
#define MP make_pair
#define f first
#define s second
#define rfor(i,b,a) for(int i=b;i>=a;i--)
#define INF 1000000007


long long mod(long long x) {
    return ((x % M + M) % M);
}
long long add(long long a, long long b) {
    return mod(mod(a) + mod(b));
}
long long mul(long long a, long long b) {
    return mod(mod(a) * mod(b));
}

int gcd(int a, int b) {
    if (a == 0) {
        return b;
    }
    return gcd(b % a, a);
}

int lcm(int a, int b) {
    return (a / gcd(a, b)) * b;
}

int fact(int n) {
    if (n == 0 || n == 1) return 1;
    else return n * fact(n - 1);
}

int ncr(int n, int r) {
    return fact(n) / (fact(n - r) * fact(r));
}


bool isPrime(int n)
{
    if (n == 1) return false;
    if (n == 2) return true;
    for (int i = 2; i <= sqrt(n); i++)
    {
        if (n % i == 0) return false;
    }
    return true;
}

void sieve(int *p) {
    for (int i = 3; i <= 1000000; i += 2) {
        p[i] = 1;
    }

    for (ll i = 3; i <= 1000000; i += 2) {
        if (p[i] == 1) {
            for (ll j = i * i; j <= 1000000; j += i) {
                p[j] = 0;
            }
        }
    }

    p[2] = 1;
    p[0] = p[1] = 0;
}

bool sortbysecdec(const pair<int, int> &a, const pair<int, int> &b)
{
    return (a.second > b.second);
}

bool sortbysecinc(const pair<int, int> &a, const pair<int, int> &b)
{
    return (a.second < b.second);
}

bool equal(pair<int, int> temp, int a) {
    return temp.second == a;
}

bool feasible(int mid, vector<int>& arr, int n, int k) {
    int pos = arr[0];
    int elements = 1;

    for (int i = 1; i < n; i++) {
        if (arr[i] - pos >= mid) {
            pos = arr[i];
            elements++;
        }

        if (elements == k) return true;
    }

    return false;
}

int check(map<char, int> freq) {
    int maxx = -1;
    char maxx_element;
    for (auto i : freq) {
        if (i.second > maxx) {
            maxx = i.second;
            maxx_element = i.first;
        }
    }

    int ans = 0;
    for (auto i : freq) {
        if (i.first != maxx_element) ans += i.second;
    }

    return ans;
}

bool check(int n) {
    int n1 = n;
    while (n) {
        if (n % 10 == 7) return false;
        n /= 10;
    }

    while (n1) {
        if (n1 % 8 == 7) return false;
        n1 /= 8;
    }

    return true;
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

#ifndef ONLINE_JUDGE
    freopen("input_codeforces.txt", "r", stdin);
    freopen("output_codeforces.txt", "w", stdout);
#endif


    int n;
    cin >> n;

    int res = 0;

    for (int i = 1; i <= n; i++) {
        if (check(i)) res++;
    }

    cout << res << endl;
}

