#include using namespace std; using ll = long long; const ll INF = 1LL << 60; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int N, Q; cin >> N >> Q; vector cost(N + 1, INF); cost[1] = 0; priority_queue, vector>, greater<>> pq; pq.emplace(0, 1); while (Q--) { int type; cin >> type; if (type == 1) { int x; cin >> x; while (!pq.empty()) { auto [c, pos] = pq.top(); pq.pop(); if (c > cost[pos]) continue; for (int d : {-1, 1}) { int nx = pos + d; if (nx < 1 || nx > N) continue; if (cost[nx] > cost[pos] + 1) { cost[nx] = cost[pos] + 1; pq.emplace(cost[nx], nx); } } } cout << cost[x] << '\n'; } else { int x; ll c; cin >> x >> c; if (cost[x] > c) { cost[x] = c; pq.emplace(c, x); } } } return 0; }