#include using namespace std; typedef long long int ll; typedef pair P; const ll MOD=1000000007; const ll INF=1000000010; const ll LINF=4000000000000000010LL; const int MAX=310; const double EPS=1e-9; int dx[4]={0,1,0,1}; int dy[4]={0,0,1,1}; struct edge{int to,cost,time;}; vector G[51]; int u[51],v[51],y[51],t[51]; int d[310][51]; int main(){ int n,c,m;cin>>n>>c>>m; for(int i=0;i>u[i]; for(int i=0;i>v[i]; for(int i=0;i>y[i]; for(int i=0;i>t[i]; for(int i=0;i,vector>,greater> > q;; for(int i=0;i<=c;i++)for(int j=0;j p=q.top(); q.pop(); int vv=p.second.second;int cc=p.second.first;int tt=p.first; for(auto e:G[vv]){ if(cc+e.cost>c)continue; if(d[cc+e.cost][e.to]<=d[cc][vv]+e.time)continue; d[cc+e.cost][e.to]=d[cc][vv]+e.time; q.push(make_pair(d[cc+e.cost][e.to],P(cc+e.cost,e.to))); } } int ans=INF; for(int i=0;i<=c;i++){ ans=min(d[i][n-1],ans); } if(ans==INF){ cout<<-1<