#include<bits/stdc++.h>
using namespace std;
typedef pair<int, int> pi;
typedef long long lint;
const int MAXN = 222;
struct maxflow{
struct edg{int pos, cap, rev, idx;};
vector<edg> gph[MAXN];
void clear(){
for(int i=0; i<MAXN; i++){
gph[i].clear();
}
}
void add_edge(int s, int e, int x){
gph[s].push_back({e, x, (int)gph[e].size(), -1});
gph[e].push_back({s, 0, (int)gph[s].size()-1, -1});
}
void add_edge(int s, int e, int x, int idx){
gph[s].push_back({e, x, (int)gph[e].size(), idx});
gph[e].push_back({s, 0, (int)gph[s].size()-1, -1});
}
int dis[MAXN], pnt[MAXN];
bool bfs(int src, int sink){
memset(dis, 0, sizeof(dis));
memset(pnt, 0, sizeof(pnt));
queue<int> que;
que.push(src);
dis[src] = 1;
while(!que.empty()){
int x = que.front();
que.pop();
for(int i=0; i<gph[x].size(); i++){
edg e = gph[x][i];
if(e.cap > 0 && !dis[e.pos]){
dis[e.pos] = dis[x] + 1;
que.push(e.pos);
}
}
}
return dis[sink] > 0;
}
int dfs(int x, int sink, int f){
if(x == sink) return f;
for(; pnt[x] < gph[x].size(); pnt[x]++){
edg e = gph[x][pnt[x]];
if(e.cap > 0 && dis[e.pos] == dis[x] + 1){
int w = dfs(e.pos, sink, min(f, e.cap));
if(w){
gph[x][pnt[x]].cap -= w;
gph[e.pos][e.rev].cap += w;
return w;
}
}
}
return 0;
}
lint match(int src, int sink){
lint ret = 0;
while(bfs(src, sink)){
int r;
while((r = dfs(src, sink, 2e9))) ret += r;
}
return ret;
}
}maxflow;
int n, m;
int ret[20005];
int main(){
freopen("cooling.in", "r", stdin);
freopen("cooling.out", "w", stdout);
cin >> n >> m;
int flow = 0;
for(int i=0; i<m; i++){
int s, e, l, r;
cin >> s >> e >> l >> r;
ret[i] += r;
maxflow.add_edge(s, e, r-l, i);
maxflow.add_edge(0, e, l);
maxflow.add_edge(s, n+1, l);
flow += l;
}
if(maxflow.match(0, n+1) != flow){
puts("NO");
return 0;
}
for(int i=1; i<=n; i++){
for(auto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