#include using namespace std; #define ll long long #define db double #define X first #define Y second #define rep(i,a,b) for(int i=(a);i<=(b);++i) #define rep0(i,a,b) for(int i=(a);i<(b);++i) #define per(i,a,b) for(int i=(a);i>=(b);--i) #define fore(i,a) for(int i=0;i=m){ans=1;break;} if(x<0)x=0; } if(!ans) { rep(i,1,n) { x+=a[i]; if(x>=m){ans=2;break;} if(x<0){ans=-1;break;} } if(!ans) { ll s=0; rep(i,1,n)s+=a[i]; if(s<=0)ans=-1; else { rep(i,1,n) { x+=a[i]; if(x>=m){ans=3;break;} } x-=s; if(!ans) { ll ss=0;ans=2+m; rep(i,1,n) { ss+=a[i]; if(ss<=0)continue; ll t=m-x-ss; ans=min(ans,3+(t+s-1)/s); } } } } } printf("%lld\n",ans); } return 0; }