N = int(input()) C = int(input()) V = int(input()) edge = [list(map(int, input().split())) for _ in range(4)] dp = [[[float('inf')]*(C+1) for _ in range(N)] for _ in range(N+1)] dp[0][0][C] = 0 res = float('inf') for i in range(1,N+1): for j in range(V): s,t,y,m = edge[0][j],edge[1][j],edge[2][j],edge[3][j] s-=1;t-=1 for k in range(y,C+1): dp[i][t][k-y] = min(dp[i][t][k-y],dp[i-1][s][k]+m) res = min(res,min(dp[i][N-1])) print(-1 if res==float('inf') else res)