#include <bits/stdc++.h>
using namespace std;
int n, m, A, B, C, F[1003], f[100003][1003];
struct road {
int x, y, p, q;
bool operator < (const road &o) const {return p < o.p;}
} s[200003];
int main() {
scanf("%d %d %d %d %d", &n, &m, &A, &B, &C);
for (int i = 1; i <= m; i++)
scanf("%d %d %d %d", &s[i].x, &s[i].y, &s[i].p, &s[i].q);
for (int i = 0; i <= 1000; i++)
F[i] = C + i * (B + i * A);
sort(s + 1, s + m + 1);
memset(f, 0x3f, sizeof f);
f[1][0] = 0;
for (register int i = 1; i <= m; i++)
for (register int j = 0; j <= s[i].p; j++)
f[s[i].y][s[i].q] = min(f[s[i].y][s[i].q], f[s[i].x][j] + F[s[i].p - j]);
int ans = 2E9;
for (int i = 0; i <= 1000; i++) ans = min(ans, f[n][i] + i);
printf("%d\n", ans);
return 0;
}