#include using namespace std; using ll = long long; using ld = long double; #define fi first #define se second #define pb push_back using T = pair; int main(){ int n,m; cin>>n>>m; vector> graph(n+2*m); vector ans(n+2*m,1e18); ans[0]=0; for(int i=0;i>k>>c; graph[n+2*i].pb({n+2*i+1,c}); for(int j=0;j>s; graph[s-1].pb({n+2*i,(s+1)/2}); graph[n+2*i+1].pb({s-1,s/2}); } } priority_queue,greater> que; que.push({0,0}); while(!que.empty()){ auto [now,dist] = que.top(); que.pop(); if(dist>ans[now]){ continue; } for(auto [next,dist2] : graph[now]){ if(ans[now]+dist2=1e18){ ans[n-1]=-1; } cout<