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

#define int long long
#define rep(i,n) for(int i=0;i<n;i++)

int N;

signed main()
{
    cin >> N;

    rep(i, N)
        cout << (2 * i + 1) % N + 1 << " " << (2 * i + 2) % N + 1 << endl;

    return 0;
}

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

void chmin(int64_t& a, int64_t b){
    a = min(a, b);
}

int main(){
    int T;
   // cin >> T;
   T=1;
    typedef pair<int64_t, int64_t> P;
    while(T--){
        int64_t X,Y;
        cin >>X>>Y;
        
        int64_t cost[6] = {0};
        cost[2] = 1;
        cost[3] = 0;
        cost[5] = 0;

        int64_t ans = 1e18;
        priority_queue<P, vector<P>, greater<P>> que;
        map<int64_t, int64_t> memo;

        auto insert = [&](int64_t v, int64_t n){
            if(v < ans && (!memo.count(n) || v < memo[n])){
                que.emplace(v, n);
                memo[n] = v;
            }
        };
        int64_t D=1;
        que.emplace(0, Y);
        while(que.size()){
            auto p = que.top(); que.pop();
            int64_t v = p.first, n = p.second;
            if(v >= ans) break;
            if(n <= 2e18/D) chmin(ans, v+abs(n-X)*D);
            for(int d : {2}){
                int r = n%d;
                int64_t v2 = v + r*D + cost[d];
                insert(v2, n/d);
                v2 = v + (d-r)*D + cost[d];
                insert(v2, n/d+1);
            }
        }
        cout <<ans<< endl;
    }
    return 0;
}
