#include <iostream>
#include <map>
#include <vector>
using namespace std;

map<int, bool> states; // default value is False
int MAX_DEPTH = 16;

int dfs(int cur, int depth = 0) {
	if(depth == MAX_DEPTH) {
		return cur - (1<<MAX_DEPTH) + 1;
	}
	
	if(states[cur] == 0) {
		states[cur] = !states[cur];
		return dfs(2*cur, depth+1);
	}
	else {
		states[cur] = !states[cur];
		return dfs(2*cur+1, depth+1);
	}
	
}

int main() {
	int until = (1LL<<(MAX_DEPTH-1));
	vector<int> pos; // 0 indexed
	for(int i = 1; i <= until; i++) {
		// cout << dfs(1) << ' ';
		pos.push_back(dfs(1));
	}
	
	cout << pos[(12344%until)]; 
	// 12344 instead of 12345 since the sequence is 0 indexed
}
