#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; assert(1<=n&&n<=1e5); assert(0<=m&&m<=1e5); vector> graph(n+2*m); vector ans(n+2*m,1e18); ans[0]=0; int ksum=0; for(int i=0;i>k>>c; ksum+=k; assert(1<=k&&k<=n); assert(1<=c&&c<=1e12); graph[n+2*i].pb({n+2*i+1,1}); graph[n+2*i+1].pb({n+2*i,1}); int si[k]; for(int j=0;j>s; assert(1<=s&&s<=n); si[j]=s; if(s%2==1){ graph[s-1].pb({n+2*i,s+c}); graph[n+2*i].pb({s-1,s+c}); } else{ graph[s-1].pb({n+2*i+1,s+c}); graph[n+2*i+1].pb({s-1,s+c}); } } for(int j=1;j,greater> que; que.push({0,0}); while(!que.empty()){ auto [now,dist] = que.top(); que.pop(); if(dist>ans[now]){ continue; } if(graph[now].size()==0){ continue; } for(auto [next,dist2] : graph[now]){ if(ans[now]+dist2=1e18){ ans[n-1]=-2; } cout<