#include <bits/stdc++.h>
using namespace std;
long long n, m, a[10010][5], k[1000010], b[1000010], c[1000010], ans, ans1 = 1e8;
int main() {
   
	cin >> n >> m;
	for(int i = 1; i <= m; i++) cin >> a[i][1] >> a[i][2] >> a[i][3] >> a[i][4];
	for(int i = 1; i <= m; i++) {
   
		for(int j = 1; j <= a[i][3]; j++)
			k[a[i][1] + j - 1] += a[i][4];
	}
	for(int i = 1; i <= n; i++) b[i] = b[i - 1] + k[i];
	for(int i = n; i >= 1; i--) c[i] = c[i + 1] + k[i];
	for(int i = 1; i <= n; i++) 
		if(b[i - 1] >= c[i] && b[i - 1] - c[i] <= ans1) {
   
			ans = i;
			ans1 = b[i - 1] - c[i];
		}
	cout << ans;
}