#include //#include using namespace std; //using namespace atcoder; int main(){ int N; int C; int V; cin>>N>>C>>V; int S[V],T[V],Y[V],M[V]; for(int i=0;i>S[i]; } for(int i=0;i>T[i]; } for(int i=0;i>Y[i]; } for(int i=0;i>M[i]; } vector>> v[N+1]; for(int i=0;i> q; q.push(make_pair(C,1)); dp[C][1]=0; while(!q.empty()){ int c=q.front().first; int n=q.front().second; q.pop(); for(int i=0;i=0&&(dp[c-ny][nn]==-1||dp[c-ny][nn]>cc)){ dp[c-ny][nn]=cc; q.push(make_pair(c-ny,nn)); } } } int mn=INT_MAX; for(int i=0;i<=C;i++){ if(dp[i][N]!=-1) mn=min(mn,dp[i][N]); } if(mn==INT_MAX) cout<<"-1"<