#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
 ll n;
 cin>>n;
 if(n<=6)
 cout<<n;
 else
 {
     int c=0;
 for(int i=7;i<=n;i++)
 {
   int te=i,r,f=0;
   while(te>0)
   {
       r=te%10;
       te/=10;
       if(r==7)
       {f=1;
       break;}
   }
   if(f==1)
   {c++;
   continue;}
   te=i;
   while(te>0)
   {
       r=te%8;
       te/=8;
       if(r==7)
       {
           f=1;
           break;
       }
   }
   if(f==1)
   c++;
 }  
 cout<<n-c;
 }
 

}
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef pair<ll, ll> p_ll;

template<class T>
void debug(T itr1, T itr2) { auto now = itr1; while(now<itr2) { cout << *now << " "; now++; } cout << endl; }
#define repr(i,from,to) for (ll i=(ll)from; i<(ll)to; i++)
#define all(vec) vec.begin(), vec.end()
#define rep(i,N) repr(i,0,N)
#define per(i,N) for (ll i=(ll)N-1; i>=0; i--)

const ll MOD = pow(10,9)+7;
const ll LLINF = pow(2,61)-1;
const ll INF = pow(2,30)-1;

vector<ll> fac;
void c_fac(ll x=pow(10,7)+10) { fac.resize(x,true); rep(i,x) fac[i] = i ? (fac[i-1]*i)%MOD : 1; }
ll inv(ll a, ll m=MOD) { ll b = m, x = 1, y = 0; while (b!=0) { ll d = a/b; a -= b*d; swap(a,b); x -= y*d; swap(x,y); } return (x+m)%m; }
ll nck(ll n, ll k) { return fac[n]*inv(fac[k]*fac[n-k]%MOD)%MOD; }
ll modpow(ll x, ll p) { ll result = 1, now = 1, pm = x; while (now<=p) { if (p&now) { result = result * pm % MOD; } now*=2; pm = pm*pm % MOD; } return result; }
ll gcd(ll a, ll b) { if (a<b) swap(a,b); return b==0 ? a : gcd(b, a%b); }
ll lcm(ll a, ll b) { return a/gcd(a,b)*b; }


int main() {
  ll N; cin >> N;
  rep(i,N) {
    ll a = i*2, b = i*2+1;
    ll tca = 0; while ((1<<tca)<=a) tca++;
    while (a>=N) { if (a&(1<<tca)) a ^= (1<<tca); tca--; }
    ll tcb = 0; while ((1<<tcb)<=b) tcb++;
    while (b>=N) { if (b&(1<<tcb)) b ^= (1<<tcb); tcb--; }
    a++; b++;
    cout << a << " " << b << endl;
  }
  return 0;
}