#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;cin>>N;
  for(int i=1;i<=N;i++)
    cout<<(i*2%N==0? N:i*2%N)<<" "<<((i*2+1)%N==0? N:(i*2+1)%N)<<endl;
}
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#include <bits/stdc++.h>

#define ll long long
#define f first 
#define s second
#define pii pair<int,int>
#define pb push_back
#define sz(x) (int)(x).size()
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()

using namespace std;

void IO(){
    #ifndef ONLINE_JUDGE
        freopen("test.txt","r",stdin);
    #endif
}

const int N = 1e6 + 7, K = 26, M = 5e3 + 5, mod = 1e9 + 7, dx[] = {0,1,-1,0}, MOD = 998244353,
                                                           dy[] = {1,0,0,-1};

int tc = 1, n, m, a[M][M], b[N], ans, k, cnt[N], grid[M][M], L[N], R[N], pre[N];

char s[N];


void test_case(){
    scanf("%d", &n);
    for(int i = 1 ; i <= n ; i++){
        bool ok = true;
        int j = i;
        while(j){
            ok &= (j % 10) != 7;
            j /= 10;
        }
        j = i;
        while(j){
            ok &= (j % 8) != 7;
            j /= 8;
        }
        ans += ok;
    }
    printf("%d\n", ans);
}

int main(){
    //IO();
    //scanf("%d", &tc);
    while(tc--){
        test_case();
    }
}
