#include <bits/stdc++.h>

#define endl "\n"
#define Ios ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
#define fi first
#define se second
#define setp(a)  fixed << setprecision(a)
#define mp make_pair
#define pb push_back
#define sz(x) (int)x.size()
#define all(x) x.begin() , x.end()
#define run(x , y) set<int>::iterator y = x.begin(); y != x.end(); ++y

#define Vll vector < ll >
#define Vi vector < int >
#define ll long long
#define ull unsigned long long

using namespace std;

const double pi = 3.14159265358979323846;
const ll Mod = (ll) 1e9 + 7;
const int Mass = (int) 2e5;
const int pr = 37;

pair <int , int> ans[150];
int Ans;
int n , m;

int main(){ Ios
	#ifdef Home
		freopen(".in", "r", stdin);
    	freopen(".out", "w", stdout);
  	#endif
  	cin >> n >> m;
  	for (int i = 1; i <= n; i++) {
  	 	ans[i].fi = 9999;
  	 	ans[i].se = -9999;
  	}
  	for (int i = 1; i <= m; i++) {
  		int l , r , t , x;
  		cin >> l >> r >> t >> x;
  		for (int s = l; s <= r; s++) {
  			if (ans[s].fi > t) {
  				ans[s].fi = t;
  				ans[s].se = x;
  			}
  			else if (ans[s].fi == t) {
  			    if (ans[s].se > x) {
  			     	ans[s].se = x;
  			    }
  			}
  		}
   	}
   	for (int i = 1; i <= n; i++) {
   	 	if (ans[i].fi == 9999)
   	 		continue;
   	 	Ans += ans[i].se;
   	}
   	cout << Ans;
  	return 0;
}


#include <bits/stdc++.h>

#define endl "\n"
#define Ios ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
#define fi first
#define se second
#define setp(a)  fixed << setprecision(a)
#define mp make_pair
#define pb push_back
#define sz(x) (int)x.size()
#define all(x) x.begin() , x.end()
#define run(x , y) set<int>::iterator y = x.begin(); y != x.end(); ++y

#define Vll vector < ll >
#define Vi vector < int >
#define ll long long
#define ull unsigned long long

using namespace std;

const double pi = 3.14159265358979323846;
const ll Mod = (ll) 1e9 + 7;
const int Mass = (int) 2e5;
const int pr = 37;

pair <int , int> ans[150];
int Ans;
int n , m;

int main(){ Ios
	#ifdef Home
		freopen(".in", "r", stdin);
    	freopen(".out", "w", stdout);
  	#endif
  	cin >> n >> m;
  	for (int i = 1; i <= m; i++) {
  		int l , r , t , x;
  		cin >> l >> r >> t >> x;
  		for (int s = l; s <= r; s++) {
  			if (ans[s].fi > t) {
  				ans[s].fi = t;
  				ans[s].se = x;
  			}
  			else if (ans[s].fi == t) {
  			    if (ans[s].se < x) {
  			     	ans[s].se = x;
  			    }
  			}
  		}
   	}
   	for (int i = 1; i <= n; i++) {
   	 /*	if (ans[i].fi == 9999)
   	 		continue;
   	 */
   		Ans += ans[i].se;
   	}
   	cout << Ans;
  	return 0;
}


#include <bits/stdc++.h>

#define endl "\n"
#define Ios ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
#define fi first
#define se second
#define setp(a)  fixed << setprecision(a)
#define mp make_pair
#define pb push_back
#define sz(x) (int)x.size()
#define all(x) x.begin() , x.end()
#define run(x , y) set<int>::iterator y = x.begin(); y != x.end(); ++y

#define Vll vector < ll >
#define Vi vector < int >
#define ll long long
#define ull unsigned long long

using namespace std;

const double pi = 3.14159265358979323846;
const ll Mod = (ll) 1e9 + 7;
const int Mass = (int) 2e5;
const int pr = 37;

pair <int , int> ans[150];
int Ans;
int n , m;

int main(){ Ios
	#ifdef Home
		freopen(".in", "r", stdin);
    	freopen(".out", "w", stdout);
  	#endif
  	cin >> n >> m;
  	for (int i = 1; i <= n; i++) {
  	 	ans[i].fi = 9999;
  	 	ans[i].se = -9999;
  	}
  	for (int i = 1; i <= m; i++) {
  		int l , r , t , x;
  		cin >> l >> r >> t >> x;
  		for (int s = l; s <= r; s++) {
  			if (ans[s].fi > t) {
  				ans[s].fi = t;
  				ans[s].se = x;
  			}
  		}
   	}
   	for (int i = 1; i <= n; i++) {
   	 	if (ans[i].fi == 9999)
   	 		continue;
   	 	Ans += ans[i].se;
   	}
   	cout << Ans;
  	return 0;
}


#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>

using namespace std;

#define SZ(X) (int)(X).size()
#define pb(X) push_back(X)
#define ALL(X) (X).begin(),(X).end()
#define ALLR(X) (X).rbegin(),(X).rend()
#define pi 3.1415926536
#define ll long long
const double EPS = 1e-9;
const int inf = 1 << 30;

ll pw(ll b, ll p)
{
    if (!p) return 1;
    ll sq = pw(b, p / 2);
    sq *= sq;
    if (p % 2) sq *= b;
    return sq;
}
ll gcd(ll a, ll b)
{
    return (b == 0 ? a : gcd(b, a % b));
}
ll sd(ll x)
{
    return x<10 ? x : x % 10 + sd(x / 10);
}
ll lcm(ll a, ll b)
{
    return ((a*b) / gcd(a, b));
}

int tt[105];
int cc[105];
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    string digit;
    int n, m, ans=0, l, r, t, c;
    cin>>n>>m;
    for(int i=0; i<m; i++)
    {
        cin>>l>>r>>t>>c;
        for(int j=l; j<=r; j++)
            if(tt[j] == 0 || tt[j] > t)
            {
                ans += c-cc[j];
                tt[j]=t;
                cc[j]=c;
            }

    }
    cout<<ans;
    return 0;
}


#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>

using namespace std;

#define SZ(X) (int)(X).size()
#define pb(X) push_back(X)
#define ALL(X) (X).begin(),(X).end()
#define ALLR(X) (X).rbegin(),(X).rend()
#define pi 3.1415926536
#define ll long long
const double EPS = 1e-9;
const int inf = 1 << 30;

ll pw(ll b, ll p)
{
    if (!p) return 1;
    ll sq = pw(b, p / 2);
    sq *= sq;
    if (p % 2) sq *= b;
    return sq;
}
ll gcd(ll a, ll b)
{
    return (b == 0 ? a : gcd(b, a % b));
}
ll sd(ll x)
{
    return x<10 ? x : x % 10 + sd(x / 10);
}
ll lcm(ll a, ll b)
{
    return ((a*b) / gcd(a, b));
}

int tt[105];
int cc[105];
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    string digit;
    int n, m, ans=0;
	scanf("%d%d", &n, &m);
	for(int i=0;i<m;i++) {
		int l, r, t, c;
		cin>>l>>r>>t>>c;
		for(int j=l;j<=r;j++)
			if(tt[j]==0 || tt[j]>t) {
				ans += c-cc[j];
				tt[j]=t;
				cc[j]=c;
			}

	}
	cout<<ans;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;

int main(){
    int n, m;
    cin>>n>>m;
    map<int, pair<int, int> > a;
    for(int i=0; i<=n; i++){
        a[i]=make_pair(1e6, 0);
    }
    for(int i=0; i<m; i++){
        int l, r, t, c;
        cin>>l>>r>>t>>c;
        for(int j=l; j<=r; j++){
            if(a[j].first > t){
                a[j].first = t;
                a[j].second = c;
            }

        }
    }
    int ans = 0;
    for(int i=0; i<=n; i++){
        ans+=a[i].second;
    }
    cout<<ans;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;

int main(){
    int n, m;
    cin>>n>>m;
    map<int, pair<int, int> > a;
    for(int i=0; i<=n; i++){
        a[i]=make_pair(1e6, 0);
    }
    for(int i=0; i<m; i++){
        int l, r, t, c;
        cin>>l>>r>>t>>c;
        for(int j=l; j<=r; j++){
            if(a[j].first > t){
                a[j].first = t;
                a[j].second = c;
            }
            else if(a[j].first == t){
                if(a[j].second < c){
                    a[j].second=c;
                }
            }
        }
    }
    int ans = 0;
    for(int i=0; i<=n; i++){
        ans+=a[i].second;
    }
    cout<<ans;
    return 0;
}


#include <iostream>
#include <math.h>
#include <string.h>
using namespace std;
void FillI(int array[], int left, int right) {
    int i = left, j = right;
    int tmp, t;
    int pivot = array[(left + right) / 2];

    /* partition */
    while (i <= j) {
        while (array[i] < pivot)
        i++;
        while (array[j] > pivot)
        j--;
        if (i <= j) {
            tmp = array[i];
            array[i] = array[j];
            array[j] = tmp;

            i++;
            j--;
        }
    };

    /* recursion */
    if (left < j)
    FillI(array, left, j);
    if (i < right)
    FillI(array, i, right);

}
int main()
{
        int  n, m;
        cin>>m >> n;
        int arr[n][4]; int mas[m];
        for(int k=0; k<m;k++)
        {
                mas[k] = 0;
        }
        for(int i=0;i<n;i++)
        {
                for(int j = 0; j<4;j++)
                {
                   cin>>arr[i][j];
                }
        }

               int k = 0;
               int c = 1;
               while(k<m)
               {
                   int curtime = 2000, money = 0;    c = k+1;
                   for(int i=0;i<n;i++)
                   {
                      if(arr[i][0]<=c && arr[i][1]>=c)
                      {
                              //mas[k] = i;
                         /*if(arr[i][2]==curtime && arr[i][3] > money)
                         {
                                curtime=arr[i][2];
                                money = arr[i][3];
                         }*/
                         if(arr[i][2]<curtime)
                         {
                                curtime=arr[i][2];
                                money = arr[i][3];
                         }

                      }
                   }
                   mas[k] = money;

                   k++;
               }

        int sum=0;
        for(int k=0; k<m;k++)
        {
                sum+=mas[k];
        }

        cout<<sum;
        return 0;
}


#include <iostream>
#include <math.h>
#include <string.h>
using namespace std;
void FillI(int array[], int left, int right) {
    int i = left, j = right;
    int tmp, t;
    int pivot = array[(left + right) / 2];

    /* partition */
    while (i <= j) {
        while (array[i] < pivot)
        i++;
        while (array[j] > pivot)
        j--;
        if (i <= j) {
            tmp = array[i];
            array[i] = array[j];
            array[j] = tmp;

            i++;
            j--;
        }
    };

    /* recursion */
    if (left < j)
    FillI(array, left, j);
    if (i < right)
    FillI(array, i, right);

}
int main()
{
        int  n, m;
        cin>>m >> n;
        int arr[n][4]; int mas[m];
        for(int k=0; k<m;k++)
        {
                mas[k] = 0;
        }
        for(int i=0;i<n;i++)
        {
                for(int j = 0; j<4;j++)
                {
                   cin>>arr[i][j];
                }
        }

               int k = 0;
               int c = 1;
               while(k<m)
               {
                   int curtime = 2000, money = 0;    c = k+1;
                   for(int i=0;i<n;i++)
                   {
                      if(arr[i][0]<=c && arr[i][1]>=c)
                      {
                              //mas[k] = i;
                         if(arr[i][2]==curtime && arr[i][3] > money)
                         {
                                curtime=arr[i][2];
                                money = arr[i][3];
                         }
                         if(arr[i][2]<curtime)
                         {
                                curtime=arr[i][2];
                                money = arr[i][3];
                         }

                      }
                   }
                   mas[k] = money;

                   k++;
               }

        int sum=0;
        for(int k=0; k<m;k++)
        {
                sum+=mas[k];
        }

        cout<<sum;
        return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
struct data{
    ll l,r,c,t;
};
data p[101];
bool cmp(data a,data b){
    return a.t<b.t;
}
int main()
{
    ll i,n,m,j;
    while(cin>>n>>m){
        for(i=0;i<m;i++){
            cin>>p[i].l>>p[i].r>>p[i].t>>p[i].c;
        }
        bool f[101];
        memset(f,0,sizeof(f));
        sort(p,p+m,cmp);
        ll cnt=0,sum=0;
        for(i=0;i<m;i++){
            if(cnt==n)break;
            for(j=p[i].l;j<=p[i].r;j++){
                if(f[j]==1)
                    continue;
                else{
                    sum+=p[i].c;
                    f[j]=1;
                    cnt++;
                }
                if(cnt==n)
                    break;
            }
        }
        cout<<sum<<endl;
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
struct data{
    ll l,r,c,t;
};
data p[101];
bool cmp(data a,data b){
    return a.t<b.t;
}
int main()
{
    ll i,n,m,j;
    while(cin>>n>>m){
        for(i=0;i<m;i++){
            cin>>p[i].l>>p[i].r>>p[i].t>>p[i].c;
        }
        bool f[101];
        memset(f,0,sizeof(f));
        sort(p,p+m,cmp);
        ll cnt=0,sum=0;
        for(i=0;i<m;i++){
            if(cnt==n)break;
            for(j=p[i].l;j<=p[i].r;j++){
                if(f[j]==1)
                    continue;
                else{
                    sum+=p[i].c;
                    f[j]=1;
                    cnt++;
                }
            }
        }
        cout<<sum<<endl;
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
struct data{
    ll l,r,c,t;
};
data p[101];
bool cmp(data a,data b){
    return a.t<b.t;
}
int main()
{
    ll i,n,m,j;
    while(cin>>n>>m){
        for(i=0;i<m;i++){
            cin>>p[i].l>>p[i].r>>p[i].t>>p[i].c;
        }
        bool f[101];
        memset(f,0,sizeof(f));
        sort(p,p+m,cmp);
        ll sum=0;
        for(i=0;i<m;i++){
            for(j=p[i].l;j<=p[i].r;j++){
                if(f[j]==1)
                    continue;
                else{
                    sum+=p[i].c;
                    f[j]=1;
                }
            }
        }
        cout<<sum<<endl;
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
struct data{
    ll l,r,c,t;
};
data p[105];
bool cmp(data a,data b){
    return a.t<b.t;
}
int main()
{
    ll i,n,m,j;
    while(cin>>n>>m){
        for(i=1;i<=m;i++){
            cin>>p[i].l>>p[i].r>>p[i].t>>p[i].c;
        }
        bool f[105];
        memset(f,0,sizeof(f));
        sort(p+1,p+m+1,cmp);
        ll sum=0;
        for(i=1;i<=m;i++){
            for(j=p[i].l;j<=p[i].r;j++){
                if(f[j]==1)
                    continue;
                else{
                    sum+=p[i].c;
                    f[j]=1;
                }
            }
        }
        cout<<sum<<endl;
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    ll i,n,m,j;
    while(cin>>n>>m){
            ll L[m+1],R[m+1],C[m+1],T[m+1];
        for(i=0;i<m;i++){
            cin>>L[i]>>R[i]>>T[i]>>C[i];
        }
        ll ans=0;
        for(i=1;i<=n;i++){
            ll p=-1,mn=1001;
            for(j=0;j<m;j++){
                if(L[j]<=i && R[j]>=i)
                    if(T[j]<mn){
                        mn=T[j];
                        p=C[j];
                    }
                }
                if(p!=-1)
                    ans+=p;
            }
        cout<<ans<<endl;
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

struct state {
    int t, i, p;
    state(int t, int i, int p) :
            t(t), i(i), p(p) {
    }
    bool operator<(const state&e) const {
        if (e.t != t)
            return t < e.t;
        return i < e.i;
    }
};

const int N = 100;
vector<state> g[N];
int n, m;

int main() {
//  freopen("a", "r", stdin);
    scanf("%d%d", &n, &m);
    for (int i = 0; i < m; ++i) {
        int l, r, t, c;
        scanf("%d%d%d%d", &l, &r, &t, &c);
        --l;
        --r;
        while (l <= r)
            g[l++].push_back(state(t, i, c));
    }
    for (int i = 0; i < n; ++i)
        sort(g[i].begin(), g[i].end());
    int res = 0;
    for (int i = 0; i < n; ++i)
        if (!g[i].empty())
            res += g[i][0].p;
    printf("%d\n", res);
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

struct state {
    int t, i, p;
    state(int t, int i, int p) :
            t(t), i(i), p(p) {
    }
    bool operator<(const state&e) const {
        if (e.t != t)
            return t < e.t;
        return i < e.i;
    }
};

const int N = 100;
vector<state> g[N];
int n, m;

int main() {
//  freopen("a", "r", stdin);
    scanf("%d%d", &n, &m);
    for (int i = 0; i < n; ++i) {
        int l, r, t, c;
        scanf("%d%d%d%d", &l, &r, &t, &c);
        --l;
        --r;
        while (l <= r)
            g[l++].push_back(state(t, i, c));
    }
    for (int i = 0; i < n; ++i)
        sort(g[i].begin(), g[i].end());
    int res = 0;
    for (int i = 0; i < n; ++i)
        if (!g[i].empty())
            res += g[i][0].p;
    printf("%d\n", res);
    return 0;
}


#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cassert>
#include <cstdio>
#include <vector>
#include <cmath>
#include <ctime>
#include <set>
#include <map>
#include <queue>
#define F first
#define S second
#define eps 1e-8
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define INF 2000000000

typedef long long ll;

using namespace std;
int n, m, ans, l, r, t, c;
pair<int, int> cur[111];
int main()
{
	ios::sync_with_stdio(0);
	cin >> n >> m;
	for(int i = 0; i < n; i++)
		cur[i] = mp(-1000, 0);
	for(int i = 0; i < m; i++){
		cin >> l >> r >> t >> c;
		for(int j = l - 1; j < r; j++){
			if(cur[j].F < -t)
				cur[j] = mp(-t, c);
		}
	}
	for(int i = 0; i < n; i++)
		ans += cur[i].S;
	cout << ans;

	return 0;
}


#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cassert>
#include <cstdio>
#include <vector>
#include <cmath>
#include <ctime>
#include <set>
#include <map>
#include <queue>
#define F first
#define S second
#define eps 1e-8
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define INF 2000000000

typedef long long ll;

using namespace std;
int n, m, ans, l, r, t, c;
pair<int, int> cur[111];
int main()
{
	ios::sync_with_stdio(0);
	cin >> n >> m;
	for(int i = 0; i < n; i++)
		cur[i] = mp(-1001, 0);
	for(int i = 0; i < m; i++){
		cin >> l >> r >> t >> c;
		for(int j = l - 1; j < r; j++){
			if(cur[j].F < -t)
				cur[j] = mp(-t, c);
		}
	}
	for(int i = 0; i < n; i++)
		ans += cur[i].S;
	cout << ans;

	return 0;
}


#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cassert>
#include <cstdio>
#include <vector>
#include <cmath>
#include <ctime>
#include <set>
#include <map>
#include <queue>
#define F first
#define S second
#define eps 1e-8
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define INF 2000000000

typedef long long ll;

using namespace std;
int n, m, ans, l, r, t, c;
pair<int, int> cur[111];
int main()
{
	ios::sync_with_stdio(0);
	cin >> n >> m;
	for(int i = 0; i < n; i++)
		cur[i] = mp(-1000, 0);
	for(int i = 0; i < m; i++){
		cin >> l >> r >> t >> c;
		for(int j = l - 1; j < r; j++)
			cur[j] = max(cur[j], mp(-t, c));
	}
	for(int i = 0; i < n; i++)
		ans += cur[i].S;
	cout << ans;

	return 0;
}


///***###                               بسم الله الرحمن الرحيم                            ###***///

/*
                    Author          : Borhan Uddin Rafi
                    University      : Begum Rokeya University,Rangpur.
                    Date            : 20 August,2020;
*/

///************************Start Of Template*************************///

#include<iostream>
#include<bits/stdc++.h>
#include<algorithm>
#include<math.h>
#define Read_Fast    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define PI acos(-1)
#define all(a) a.begin(),a.end()
#define f first
#define s second
#define pb push_back
#define ppb pop_back
#define pf push_front
#define ppf pop_front
#define mp make_pair
#define f0(i,n) for(i=0;i<n;i++)
#define f1(i,n) for(i=1;i<n;i++)
#define f1n(i,n) for(i=1;i<=n;i++)
#define szf sizeof()
#define sz size()
#define ln length()
#define mem(x,r) memset(x,r,sizeof(x))
#define inf 1000000000000
using namespace std;
using ll=long long;
const int N=1e1;

map<string,string>maap;

//////graph////////
vector<int>circle;
bool vis[N];
int parent[N];
int chk[N];
int color[N];
int tim[2][N];
int dis[N];
int position[N];
vector<int>adj[N];
vector<int>adj1[N];
//vector<pair<ll,ll>>adj[N];
vector<int>graph[N];
bool has_cycle;
int maxdis,maxnode,Totnode,depth=1;
bool ok;
queue<int>q;
stack<int>stk;
vector<int>solution;
int indegree[N];
int go[N];
int to[N];
map<int,int>mp1;
vector<pair<int,int>>vec;

//////graph////////

/*** this solution will not work if freopen  terminal are open................
    If you close that freopen then its work here.
    But before submission you need to open freopen line when submit .text file***/

////calculate the path //////

//////////main function////////

int main()
{
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    Read_Fast;
    int t;
    // cin>>t;
    int cas=0;
    // while(t--)
    // {
    ll n,m,i,j,cnt1=0,cnt2=0,cnt=0,even=0,odd=0,len,k,r,l,z=0,x=0,y=0,flag=0,sum=0;
    ll a=0,b=0,c=0,d=0,ans=0LL,rem,quot,zero=0,fst=0,null=0,snd=0,lst=0,rone=0,one=0,pos=0,neg=0,mn=INT_MAX,mx=INT_MIN;

    char ch;

    ////Time/////
    int h1,h2,m1,m2,h;

    ////motion ////
    int velo1,velo2,ac1,ac2,time;

    /////Graph///
    int node,edge,u,v,cost;
    int best,worst;
    double nd,ad,bd,xd;
    string str,str1="",str2="",str3="",strstore1="",strstore2="";

    //////Input Node //////

    cin>>n>>m;
    int arr[110],brr[110],cost[110],tim[110];
    for(int i=0; i<m; i++)
    {
        cin>>arr[i]>>brr[i]>>tim[i]>>cost[i];
    }
    for(int i=1; i<=n; i++)
    {
        k=100000;
        cnt=0;
        for(int j=0; j<m; j++)
        {
            if(brr[j]>=i && i>=arr[j])
            {
                if(k>tim[j])
                {
                    cnt=cost[j];
                    k=tim[j];
                }
            }
        }
        ans+=cnt;
    }

    cout<<cnt<<endl;
    //}
    return 0;
    //////***###            ٱلْحَمْدُ لِلَّٰهِ          ###***//////

}


///***###                               بسم الله الرحمن الرحيم                            ###***///

/*
                    Author          : Borhan Uddin Rafi
                    University      : Begum Rokeya University,Rangpur.
                    Date            : 20 August,2020;
*/

///************************Start Of Template*************************///

#include<iostream>
#include<bits/stdc++.h>
#include<algorithm>
#include<math.h>
#define Read_Fast    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define PI acos(-1)
#define all(a) a.begin(),a.end()
#define f first
#define s second
#define pb push_back
#define ppb pop_back
#define pf push_front
#define ppf pop_front
#define mp make_pair
#define f0(i,n) for(i=0;i<n;i++)
#define f1(i,n) for(i=1;i<n;i++)
#define f1n(i,n) for(i=1;i<=n;i++)
#define szf sizeof()
#define sz size()
#define ln length()
#define mem(x,r) memset(x,r,sizeof(x))
#define inf 1000000000000
using namespace std;
using ll=long long;
const int N=1e1;

map<string,string>maap;

//////graph////////
vector<int>circle;
bool vis[N];
int parent[N];
int chk[N];
int color[N];
int tim[2][N];
int dis[N];
int position[N];
vector<int>adj[N];
vector<int>adj1[N];
//vector<pair<ll,ll>>adj[N];
vector<int>graph[N];
bool has_cycle;
int maxdis,maxnode,Totnode,depth=1;
bool ok;
queue<int>q;
stack<int>stk;
vector<int>solution;
int indegree[N];
int go[N];
int to[N];
map<int,int>mp1;
vector<pair<int,int>>vec;

//////graph////////

/*** this solution will not work if freopen  terminal are open................
    If you close that freopen then its work here.
    But before submission you need to open freopen line when submit .text file***/

////calculate the path //////

//////////main function////////

int main()
{
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    Read_Fast;
    int t;
    // cin>>t;
    int cas=0;
    // while(t--)
    // {
    ll n,m,i,j,cnt1=0,cnt2=0,cnt=0,even=0,odd=0,len,k,r,l,z=0,x=0,y=0,flag=0,sum=0;
    ll a=0,b=0,c=0,d=0,ans=0LL,rem,quot,zero=0,fst=0,null=0,snd=0,lst=0,rone=0,one=0,pos=0,neg=0,mn=INT_MAX,mx=INT_MIN;

    char ch;

    ////Time/////
    int h1,h2,m1,m2,h;

    ////motion ////
    int velo1,velo2,ac1,ac2,time;

    /////Graph///
    int node,edge,u,v,cost;
    int best,worst;
    double nd,ad,bd,xd;
    string str,str1="",str2="",str3="",strstore1="",strstore2="";

    //////Input Node //////

    cin>>n>>m;
    int arr[110];
    int brr[110];
    int cst[110];
    int tim[110];
    for(int i=0; i<m; i++)
    {
        cin>>arr[i]>>brr[i]>>tim[i]>>cst[i];
    }
    for(int i=1; i<=n; i++)
    {
        k=100000;
        cnt=0;
        for(int j=0; j<m; j++)
        {
            if(brr[j]>=i && i>=arr[j])
            {
                if(k>tim[j])
                {
                    cnt=cst[j];
                    k=tim[j];
                }
            }
        }
        ans+=cnt;
    }

    cout<<cnt<<endl;
    //}
    return 0;
    //////***###            ٱلْحَمْدُ لِلَّٰهِ          ###***//////

}


///***###                               بسم الله الرحمن الرحيم                            ###***///

/*
                    Author          : Borhan Uddin Rafi
                    University      : Begum Rokeya University,Rangpur.
                    Date            : 20 August,2020;
*/

///************************Start Of Template*************************///

#include<iostream>
#include<bits/stdc++.h>
#include<algorithm>
#include<math.h>
#define Read_Fast    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define PI acos(-1)
#define all(a) a.begin(),a.end()
#define f first
#define s second
#define pb push_back
#define ppb pop_back
#define pf push_front
#define ppf pop_front
#define mp make_pair
#define f0(i,n) for(i=0;i<n;i++)
#define f1(i,n) for(i=1;i<n;i++)
#define f1n(i,n) for(i=1;i<=n;i++)
#define szf sizeof()
#define sz size()
#define ln length()
#define mem(x,r) memset(x,r,sizeof(x))
#define inf 1000000000000
using namespace std;
using ll=long long;
const int N=1e1;

map<string,string>maap;

//////graph////////
vector<int>circle;
bool vis[N];
int parent[N];
int chk[N];
int color[N];
int tim[2][N];
int dis[N];
int position[N];
vector<int>adj[N];
vector<int>adj1[N];
//vector<pair<ll,ll>>adj[N];
vector<int>graph[N];
bool has_cycle;
int maxdis,maxnode,Totnode,depth=1;
bool ok;
queue<int>q;
stack<int>stk;
vector<int>solution;
int indegree[N];
int go[N];
int to[N];
map<int,int>mp1;
vector<pair<int,int>>vec;

//////graph////////

/*** this solution will not work if freopen  terminal are open................
    If you close that freopen then its work here.
    But before submission you need to open freopen line when submit .text file***/

////calculate the path //////

//////////main function////////

int main()
{
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    Read_Fast;
    int t;
    // cin>>t;
    int cas=0;
    // while(t--)
    // {
    ll n,m,i,j,cnt1=0,cnt2=0,cnt=0,even=0,odd=0,len,k,r,l,z=0,x=0,y=0,flag=0,sum=0;
    ll a=0,b=0,c=0,d=0,ans=0LL,rem,quot,zero=0,fst=0,null=0,snd=0,lst=0,rone=0,one=0,pos=0,neg=0,mn=INT_MAX,mx=INT_MIN;

    char ch;

    ////Time/////
    int h1,h2,m1,m2,h;

    ////motion ////
    int velo1,velo2,ac1,ac2,time;

    /////Graph///
    int node,edge,u,v,cost;
    int best,worst;
    double nd,ad,bd,xd;
    string str,str1="",str2="",str3="",strstore1="",strstore2="";

    //////Input Node //////

    cin>>n>>m;
    int arr[110];
    int brr[110];
    int cst[110];
    int tim[110];
    for(int i=0; i<m; i++)
    {
        cin>>arr[i]>>brr[i]>>tim[i]>>cst[i];
    }
    for(int i=1; i<=n; i++)
    {
        k=100000;
        cnt=0;
        for(int j=0; j<m; j++)
        {
            if(brr[j]>=i && i>=arr[j])
            {
                if(k>tim[j])
                {
                    cnt=cst[j];
                    k=tim[j];
                }
            }
        }
        ans+=cnt;
    }

    cout<<ans<<endl;
    //}
    return 0;
    //////***###            ٱلْحَمْدُ لِلَّٰهِ          ###***//////

}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int sec,pla,L,R,T,C, ar[1010], profit[1010],i,j;
    scanf("%d %d",&sec, &pla);
    memset(ar,-1,sizeof(ar));
    memset(profit,-1,sizeof(profit));
    for(j=0;j<pla;j++)
    {
        scanf("%d %d %d %d",&L,&R,&T,&C);
        for(i=L; i<=R; i++)
        {
            if(ar[i] == -1 || ar[i] >= T)
            {
                if(ar[i] == T){if(C>profit[i]){ ; } }
                else{
                    profit[i] = C;
                }
                ar[i] = T;
            }
        }
    }
    int sum = 0;
    for(i=1; i<=sec;i++)
    {
        if(profit[i] != -1)
        {
            sum += profit[i];
        //printf("profit[i] = %d\n",profit[i]);
        }
    }
    printf("%d\n",sum);
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int sec,pla,L,R,T,C, ar[1010], profit[1010],i,j;
    scanf("%d %d",&sec, &pla);
    memset(ar,-1,sizeof(ar));
    memset(profit,-1,sizeof(profit));
    for(j=0;j<pla;j++)
    {
        scanf("%d %d %d %d",&L,&R,&T,&C);
        for(i=L; i<=R; i++)
        {
            if(ar[i] == -1 || ar[i] >= T)
            {
                if(ar[i] == T){if(C>profit[i]){profit[i] = C; } }
                else{
                    profit[i] = C;
                }
                ar[i] = T;
            }
        }
    }
    int sum = 0;
    for(i=1; i<=sec;i++)
    {
        if(profit[i] != -1)
        {
            sum += profit[i];
        //printf("profit[i] = %d\n",profit[i]);
        }
    }
    printf("%d\n",sum);
}


/*
*
*	FileName:
*	Created By: r3gz3n
*	Description:
*
*/

#include <iostream>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <istream>
#include <ostream>
#include <sstream>
#include <fstream>
#include <set>
#include <list>
#include <map>
#include <utility>
#include <stack>
#include <queue>
#include <cmath>
#include <iomanip>
#include <algorithm>

#define ll long long
#define ull unsigned long long
#define MP make_pair
#define PB push_back
#define FOR(i, a, b, c) for(int i = a;i < b;i += c)
#define FORI(i, a, b, c) for(int i = a;i > b;i -= c)

template<class T> inline T gcd(T a, T b) { while(b) b ^= a ^= b ^= a %= b; return a; }
template<class T> inline T pow(T a, T b, T c){ T re = 1; while(b){ if(b & 1) re = (re * a) % c; a = (a * a) % c; b >>= 1; } return re; }
template<class T> inline void read(T&x){bool fu=0;char c;for(c=getchar();c<=32;c=getchar());if(c=='-')fu=1,c=getchar();for(x=0;c>32;c=getchar())x=x*10+c-'0';if(fu)x=-x;};
template<class T> inline void read(T&x,T&y){read(x);read(y);}
template<class T> inline void read(T&x,T&y,T&z){read(x);read(y);read(z);}

using namespace std;
typedef pair <int, int> PII;
typedef pair <int, pair<int, int> > PPII;
const int MAX = 105;
ll t[MAX], c[MAX], T[MAX], W[MAX];

int main()
{
    freopen("input.txt", "r", stdin);
    int n, m, l, r;
    read(n, m);
    FOR(i, 1, n+1, 1)
        T[i] = 1005, W[i] = -1;
    FOR(i, 0, m, 1)
    {
        read(l, r);
        read(t[i], c[i]);
        FOR(j, l, r+1, 1)
        {
            if(t[i] < T[j])
                T[j] = t[i], W[j] = i;
            else if(t[i] == T[j] and c[W[j]] < c[i])
                W[j] = i;
        }
    }
    ll ans = 0;
    FOR(i, 1, n+1, 1)
    {
        //cout << W[i] << endl;
        ans += (c[W[i]]);
    }
    cout << ans << endl;
    return 0;
}


/*
*
*	FileName:
*	Created By: r3gz3n
*	Description:
*
*/

#include <iostream>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <istream>
#include <ostream>
#include <sstream>
#include <fstream>
#include <set>
#include <list>
#include <map>
#include <utility>
#include <stack>
#include <queue>
#include <cmath>
#include <iomanip>
#include <algorithm>

#define ll long long
#define ull unsigned long long
#define MP make_pair
#define PB push_back
#define FOR(i, a, b, c) for(int i = a;i < b;i += c)
#define FORI(i, a, b, c) for(int i = a;i > b;i -= c)

template<class T> inline T gcd(T a, T b) { while(b) b ^= a ^= b ^= a %= b; return a; }
template<class T> inline T pow(T a, T b, T c){ T re = 1; while(b){ if(b & 1) re = (re * a) % c; a = (a * a) % c; b >>= 1; } return re; }
template<class T> inline void read(T&x){bool fu=0;char c;for(c=getchar();c<=32;c=getchar());if(c=='-')fu=1,c=getchar();for(x=0;c>32;c=getchar())x=x*10+c-'0';if(fu)x=-x;};
template<class T> inline void read(T&x,T&y){read(x);read(y);}
template<class T> inline void read(T&x,T&y,T&z){read(x);read(y);read(z);}

using namespace std;
typedef pair <int, int> PII;
typedef pair <int, pair<int, int> > PPII;
const int MAX = 105;
ll t[MAX], c[MAX], T[MAX], W[MAX];

int main()
{
    //freopen("input.txt", "r", stdin);
    int n, m, l, r;
    read(n, m);
    FOR(i, 1, n+1, 1)
        T[i] = 1005, W[i] = -1;
    FOR(i, 0, m, 1)
    {
        read(l, r);
        read(t[i], c[i]);
        FOR(j, l, r+1, 1)
        {
            if(t[i] < T[j])
                T[j] = t[i], W[j] = i;
            else if(t[i] == T[j] and c[W[j]] < c[i])
                W[j] = i;
        }
    }
    ll ans = 0;
    FOR(i, 1, n+1, 1)
    {
        //cout << W[i] << endl;
        ans += (c[W[i]]);
    }
    cout << ans << endl;
    return 0;
}


/*
*
*	FileName:
*	Created By: r3gz3n
*	Description:
*
*/

#include <iostream>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <istream>
#include <ostream>
#include <sstream>
#include <fstream>
#include <set>
#include <list>
#include <map>
#include <utility>
#include <stack>
#include <queue>
#include <cmath>
#include <iomanip>
#include <algorithm>

#define ll long long
#define ull unsigned long long
#define MP make_pair
#define PB push_back
#define FOR(i, a, b, c) for(int i = a;i < b;i += c)
#define FORI(i, a, b, c) for(int i = a;i > b;i -= c)

template<class T> inline T gcd(T a, T b) { while(b) b ^= a ^= b ^= a %= b; return a; }
template<class T> inline T pow(T a, T b, T c){ T re = 1; while(b){ if(b & 1) re = (re * a) % c; a = (a * a) % c; b >>= 1; } return re; }
template<class T> inline void read(T&x){bool fu=0;char c;for(c=getchar();c<=32;c=getchar());if(c=='-')fu=1,c=getchar();for(x=0;c>32;c=getchar())x=x*10+c-'0';if(fu)x=-x;};
template<class T> inline void read(T&x,T&y){read(x);read(y);}
template<class T> inline void read(T&x,T&y,T&z){read(x);read(y);read(z);}

using namespace std;
typedef pair <int, int> PII;
typedef pair <int, pair<int, int> > PPII;
const int MAX = 105;
ll t[MAX], c[MAX], T[MAX], W[MAX];

int main()
{
    freopen("input.txt", "r", stdin);
    int n, m, l, r;
    read(n, m);
    FOR(i, 1, n+1, 1)
        T[i] = 1005, W[i] = -1;
    FOR(i, 0, m, 1)
    {
        read(l, r);
        read(t[i], c[i]);
        FOR(j, l, r+1, 1)
        {
            if(t[i] < T[j])
                T[j] = t[i], W[j] = i;
            //else if(t[i] == T[j] and c[W[j]] > c[i])
            //    W[j] = i;
        }
    }
    ll ans = 0;
    FOR(i, 1, n+1, 1)
    {
        //cout << W[i] << endl;
        if(c[W[i]] > -1)
            ans += (c[W[i]]);
    }
    cout << ans << endl;
    return 0;
}


/*
*
*	FileName:
*	Created By: r3gz3n
*	Description:
*
*/

#include <iostream>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <istream>
#include <ostream>
#include <sstream>
#include <fstream>
#include <set>
#include <list>
#include <map>
#include <utility>
#include <stack>
#include <queue>
#include <cmath>
#include <iomanip>
#include <algorithm>

#define ll long long
#define ull unsigned long long
#define MP make_pair
#define PB push_back
#define FOR(i, a, b, c) for(int i = a;i < b;i += c)
#define FORI(i, a, b, c) for(int i = a;i > b;i -= c)

template<class T> inline T gcd(T a, T b) { while(b) b ^= a ^= b ^= a %= b; return a; }
template<class T> inline T pow(T a, T b, T c){ T re = 1; while(b){ if(b & 1) re = (re * a) % c; a = (a * a) % c; b >>= 1; } return re; }
template<class T> inline void read(T&x){bool fu=0;char c;for(c=getchar();c<=32;c=getchar());if(c=='-')fu=1,c=getchar();for(x=0;c>32;c=getchar())x=x*10+c-'0';if(fu)x=-x;};
template<class T> inline void read(T&x,T&y){read(x);read(y);}
template<class T> inline void read(T&x,T&y,T&z){read(x);read(y);read(z);}

using namespace std;
typedef pair <int, int> PII;
typedef pair <int, pair<int, int> > PPII;
const int MAX = 105;
ll t[MAX], c[MAX], T[MAX], W[MAX];

int main()
{
    //freopen("input.txt", "r", stdin);
    int n, m, l, r;
    read(n, m);
    FOR(i, 1, n+1, 1)
        T[i] = 1005, W[i] = -1;
    FOR(i, 0, m, 1)
    {
        read(l, r);
        read(t[i], c[i]);
        FOR(j, l, r+1, 1)
        {
            if(t[i] < T[j])
                T[j] = t[i], W[j] = i;
            //else if(t[i] == T[j] and c[W[j]] > c[i])
            //    W[j] = i;
        }
    }
    ll ans = 0;
    FOR(i, 1, n+1, 1)
    {
        //cout << W[i] << endl;
        if(c[W[i]] > -1)
            ans += (c[W[i]]);
    }
    cout << ans << endl;
    return 0;
}


/*
*
*	FileName:
*	Created By: r3gz3n
*	Description:
*
*/

#include <iostream>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <istream>
#include <ostream>
#include <sstream>
#include <fstream>
#include <set>
#include <list>
#include <map>
#include <utility>
#include <stack>
#include <queue>
#include <cmath>
#include <iomanip>
#include <algorithm>

#define ll long long
#define ull unsigned long long
#define MP make_pair
#define PB push_back
#define FOR(i, a, b, c) for(int i = a;i < b;i += c)
#define FORI(i, a, b, c) for(int i = a;i > b;i -= c)

template<class T> inline T gcd(T a, T b) { while(b) b ^= a ^= b ^= a %= b; return a; }
template<class T> inline T pow(T a, T b, T c){ T re = 1; while(b){ if(b & 1) re = (re * a) % c; a = (a * a) % c; b >>= 1; } return re; }
template<class T> inline void read(T&x){bool fu=0;char c;for(c=getchar();c<=32;c=getchar());if(c=='-')fu=1,c=getchar();for(x=0;c>32;c=getchar())x=x*10+c-'0';if(fu)x=-x;};
template<class T> inline void read(T&x,T&y){read(x);read(y);}
template<class T> inline void read(T&x,T&y,T&z){read(x);read(y);read(z);}

using namespace std;
typedef pair <int, int> PII;
typedef pair <int, pair<int, int> > PPII;
const int MAX = 105;
ll t[MAX], c[MAX], T[MAX], W[MAX];

int main()
{
    //freopen("input.txt", "r", stdin);
    int n, m, l, r;
    read(n, m);
    FOR(i, 1, n+1, 1)
        T[i] = 1005, W[i] = -1;
    FOR(i, 0, m, 1)
    {
        read(l, r);
        read(t[i], c[i]);
        FOR(j, l, r+1, 1)
        {
            if(t[i] < T[j])
                T[j] = t[i], W[j] = i;
            else if(t[i] == T[j] and c[W[j]] > c[i])
                W[j] = i;
        }
    }
    ll ans = 0;
    FOR(i, 1, n+1, 1)
    {
        //cout << W[i] << endl;
        ans += (c[W[i]]);
    }
    cout << ans << endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;

struct athlete{
    int l,r,t,c;
    athlete(){}
    athlete(int _l, int _r, int _t, int _c):
        l(_l),r(_r),t(_t),c(_c){}

};

int main(){
    int n, m, l, r, c, t;
    while( cin >> n >> m){
         athlete arr[m];

         for(int i = 0; i < m; i++) cin >> arr[i].l >> arr[i].r >> arr[i].t >> arr[i].c;

         int sol = 0;
         for(int i = 1; i <= n; i++){
            int bestT = 100000, profit = 0;
            for(int j = 0; j < m; j++){
                if(arr[j].l <= i && i <= arr[j].r ){
                    if(arr[j].t < bestT){
                        bestT = arr[j].t;
                        profit = arr[j].c;
                    }else if( arr[j].t == bestT){
                        profit = max(profit, arr[j].c);
                    }
                }
            }
            //cout << i << "  "<< profit << endl;
            sol +=  profit;

         }

         cout << sol << endl;
    }
}


#include<bits/stdc++.h>
using namespace std;

struct athlete{
    int l,r,t,c;
    athlete(){}
    athlete(int _l, int _r, int _t, int _c):
        l(_l),r(_r),t(_t),c(_c){}

};

int main(){
    int n, m, l, r, c, t;
    while( cin >> n >> m){
         athlete arr[m];

         for(int i = 0; i < m; i++) cin >> arr[i].l >> arr[i].r >> arr[i].t >> arr[i].c;

         int sol = 0;
         for(int i = 1; i <= n; i++){
            int bestT = 100000, profit = 0;
            for(int j = 0; j < m; j++){
                if(arr[j].l <= i && i <= arr[j].r ){
                    if(arr[j].t < bestT){
                        bestT = arr[j].t;
                        profit = arr[j].c;
                    }
                }
            }
            //cout << i << "  "<< profit << endl;
            sol +=  profit;

         }

         cout << sol << endl;
    }
}


#include <bits/stdc++.h>
#define MOD 1000000007

using namespace std;

typedef unsigned long long ll;
typedef pair<int,int> ii;

int main()
{
    int n,m;
    cin>>n>>m;
    int sp[m+1],pr[m+1],mi[n];
    for(int ctr1=0;ctr1<n;ctr1++)
        mi[ctr1]=m;
    sp[m]=1001;
    pr[m]=0;
    for(int ctr1=0;ctr1<m;ctr1++){
        int l,r;
        cin>>l>>r;
        cin>>sp[ctr1]>>pr[ctr1];
        l--,r--;
        for(int ctr2=l;ctr2<=r;ctr2++){
            if(sp[ctr1]<sp[mi[ctr2]]){
                mi[ctr2]=ctr1;
            }
        }
    }
    int rez=0;
    for(int ctr1=0;ctr1<n;ctr1++){
        rez+=pr[mi[ctr1]];
    }
    cout<<rez;
    return 0;
}

//36395459181


#include <bits/stdc++.h>
#define MOD 1000000007

using namespace std;

typedef unsigned long long ll;
typedef pair<int,int> ii;

int main()
{
    int n,m;
    cin>>n>>m;
    int sp[n+1],pr[n+1],mi[n];
    for(int ctr1=0;ctr1<n;ctr1++)
        mi[ctr1]=n;
    sp[n]=1001;
    pr[n]=0;
    for(int ctr1=0;ctr1<m;ctr1++){
        int l,r;
        cin>>l>>r;
        cin>>sp[ctr1]>>pr[ctr1];
        l--,r--;
        for(int ctr2=l;ctr2<=r;ctr2++){
            if(sp[ctr1]<sp[mi[ctr2]]){
                mi[ctr2]=ctr1;
            }
        }
    }
    int rez=0;
    for(int ctr1=0;ctr1<n;ctr1++){
        rez+=pr[mi[ctr1]];
    }
    cout<<rez;
    return 0;
}

//36395459181


#include <bits/stdc++.h>
#include <iostream>

using namespace std;

int main()
{
    int n,m,A[100][4],a,b,i,j,time=1001,result=0;
    cin>>n>>m;
    for(i=0;i<m;i++){
        for(j=0;j<4;j++){
            cin>>A[i][j];
        }
    }
    for(i=1;i<=n;i++){
            time=1001;
        for(j=0;j<m;j++){
            if(i>=A[j][0]&&i<=A[j][1]){
                if(A[j][2]<time){
                    b=j;
                    time=A[j][2];
                }
            }
        }
        if(time!=1001)
        result+=A[b][3];
       // cout<<A[b][3]<<endl;
    }
    cout<<result;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define SZ(X) (int)(X).size()
#define ALL(X) (X).begin(),(X).end()
#define ALLR(X) (X).rbegin(),(X).rend()
using namespace std;

struct par {
	int time;
	int id;
	int profit;
};

bool comp(const par &p1, const par &p2) {
	if (p1.time < p2.time)
		return true;
	if (p1.id < p2.id)
		return true;

	return false;
}

int main() {

	vector<par> v[101];
	par p;
	int n, m;
	int l, r, t, c;
	cin >> n >> m;
	for (int i = 1; i <= m; ++i) {
		cin >> l >> r >> t >> c;
		p.id = i;
		p.time = t;
		p.profit = c;
		for (int j = l; j <= r; ++j) {
			v[j].push_back(p);
		}

	}
	int res = 0;
	for (int i = 1; i <= n; ++i) {
		sort(ALL(v[i]), comp);
		if (v[i].size() > 0) {
			res += v[i][0].profit;
		}
	}
	cout << res << endl;
	return 0;

}


#include <bits/stdc++.h>
using namespace std;
#define SZ(X) (int)(X).size()
#define ALL(X) (X).begin(),(X).end()
#define ALLR(X) (X).rbegin(),(X).rend()
using namespace std;

struct par {
	int time;
	int id;
	int profit;
};

bool comp(const par &p1, const par &p2) {
	if (p1.time <p2.time)
		return true;
	if(p1.time==p2.time){
		return p1.id <p2.id;
	}
	return false;
}

int main() {

	vector<par> v[120];
	par p;
	int n, m;
	int l, r, t, c;
	cin >> n >> m;
	for (int i = 1; i <= m; ++i) {
		cin >> l >> r >> t >> c;
		p.id = i;
		p.time = t;
		p.profit = c;
		for (int j = l; j <= r; ++j) {
			v[j].push_back(p);
		}

	}
	int res = 0;
	for (int i = 1; i <= n; ++i) {
		sort(ALL(v[i]), comp);
		if (v[i].size() > 0) {
			res += v[i][0].profit;
		}
	}
	cout << res << endl;
	return 0;

}


#include <bits/stdc++.h>
using namespace std;
const int maxn = 100;
int menor[maxn+3], vencedor[maxn+3];
int main(){
	int n, m;
	cin >> n >> m;
	for(int i = 0; i<n; i++){
		menor[i] = INT_MAX;
		vencedor[i] = 0;
	}
	for(int i = 0; i<m; i++){
		int l, r, t, c;
		cin >> l >> r >> t >> c;
		l--, r--;
		for(int j = l; j<=r; j++){
			if(menor[j] > t){
				menor[j] = t;
				vencedor[j] = c;
			}
		}
	}
	int ans = 0;
	for(int i = 0; i<n; i++){
		ans+=vencedor[i];
	}
	cout << ans <<endl;

	return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int maxN = 100 + 5;
int vis[maxN];
struct Node{
	int l,r,t,c,i;
	Node(int l = 0,int r = 0,int t = 0,int c = 0,int i=0):l(l),r(r),t(t),c(c),i(i){

	}
	bool operator < (const Node &nn)const{
		// 速度相同
		if(  nn.t ==  t ){
			if(i==nn.i){
				// 钱多的
				return c>nn.c;
			}
			// 编号小的获胜
			return i<nn.i;
		}
		// 速度小的获胜
		return t < nn.t;
	}
}nodes[maxN];
int n,m;
int main(){
	cin>>n >> m;
	for(int i=0;i<m;i++){
		cin>>nodes[i].l >> nodes[i].r>>nodes[i].t>>nodes[i].c;
		nodes[i].i = i;
	}
	sort(nodes,nodes+m);
	long long res = 0;
	for(int i=0;i<m;i++){
//		cout<<nodes[i].l<<" " << nodes[i].r << " "<< nodes[i].t <<" "<< nodes[i].c<<endl;
		for(int j=nodes[i].l;j<=nodes[i].r;j++){
			if(!vis[j]){
				vis[j]=1;
				res+=nodes[i].c;
			}
		}
	}
	cout<<res<<endl;
}


#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

int main() {
  int i, j, k, x;
  int sections, parts;
  vector<pair<int, int>> min_time(101, make_pair(INT_MAX, 0));
  int t, c;

  cin >> sections >> parts;

  for (i = 0; i < parts; i++) {
    cin >> j >> k >> t >> c;
    for (x = j; x <= k; x++) {
      if (get<0>(min_time[x]) > t) {
        min_time[x] = make_pair(t, c);
      }
      if ((get<0>(min_time[x]) == t) && (get<1>(min_time[x]) < c)) {
        min_time[x] = make_pair(t, c);
      }
    }
  }

  int sum = 0;
  for (i = 1; i <= sections; i++) {
    sum += get<1>(min_time[i]);
    // cout << get<1>(min_time[i]) << endl;
  }

  cout << sum;
}


#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

int main() {
  int i, j, k, x;
  int sections, parts;
  vector<pair<int, int>> min_time(101, make_pair(INT_MAX, 0));
  int t, c;

  cin >> sections >> parts;

  for (i = 0; i < parts; i++) {
    cin >> j >> k >> t >> c;
    for (x = j; x <= k; x++) {
      if (get<0>(min_time[x]) > t) {
        min_time[x] = make_pair(t, c);
      }
      // if ((get<0>(min_time[x]) == t) && (get<1>(min_time[x]) < c)) {
      //   min_time[x] = make_pair(t, c);
      // }
    }
  }

  int sum = 0;
  for (i = 1; i <= sections; i++) {
    sum += get<1>(min_time[i]);
    // cout << get<1>(min_time[i]) << endl;
  }

  cout << sum;
}


#include <iostream>
#include <math.h>
#include <vector>
#include <algorithm>
#include <queue>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
#define dist(a,b) abs((a)-(b))

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define lb lower_bound
#define ub upper_bound

void settings(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
}
const int MOD = 1000000007;
int n;

int main(int argc, char** argv) {
	settings(); //don't tough it lol
	int n,m; cin>>n>>m;
	pair<pii,pii> pl[m]; //begin,end,time,money
	pii area[n]; fill(area,area+n,mp(MOD,MOD));

	FOR(i,0,m){
		cin>>pl[i].ff.ff>>pl[i].ff.ss>>pl[i].ss.ff>>pl[i].ss.ss;
		FOR(j,pl[i].ff.ff-1,pl[i].ff.ss){
			if (area[j].ff>pl[i].ss.ff || area[j].ff==MOD){
				area[j].ff=pl[i].ss.ff;
				area[j].ss=i;
			}
		}
	}
	int s = 0;
	FOR(i,0,n){
		if (area[i].ff!=MOD){
			s += pl[area[i].ss].ss.ss;
		}
		//cout<<"first runned "<<i+1<<" area is "<<area[i].ss+1<<"\n";
	}
	cout<<s;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;

typedef struct {
int time;
int cost;
} bet;

int main(){
int n,m;
cin>>n>>m;
bet b[105];
int i,j,k;
for(i=1;i<=n;i++)
{
    b[i].time=2000;
    b[i].cost=0;
}

    for(i=1;i<=m;i++){
        int l,r,t,c;
       cin>>l>>r>>t>>c;
       for(j=l;j<=r;j++){
        if(b[j].time>t){
            b[j].cost=c;
            b[j].time=t;
        }
        if(b[j].time==t){
            b[j].cost=max(c,b[j].cost);
        }

       }

    }
    int ans=0;
for(i=1;i<=n;i++){
        ans=ans+b[i].cost;
}
cout<<ans<<endl;

}


#include<bits/stdc++.h>
using namespace std;

typedef struct {
int time;
int cost;
} bet;

int main(){
int n,m;
cin>>n>>m;
bet b[105];
int i,j,k;
for(i=1;i<=n;i++)
{
    b[i].time=2000;
    b[i].cost=0;
}

    for(i=1;i<=m;i++){
        int l,r,t,c;
       cin>>l>>r>>t>>c;
       for(j=l;j<=r;j++){
        if(b[j].time>t){
            b[j].cost=c;
            b[j].time=t;
        }
       }

    }
    int ans=0;
for(i=1;i<=n;i++){
        ans=ans+b[i].cost;
}
cout<<ans<<endl;

}


#include<bits/stdc++.h>
using namespace std;

typedef struct {
int time;
int cost;
} bet;

int main(){
int n,m;
cin>>n>>m;
bet b[105];
int i,j,k;
for(i=1;i<=n;i++)
{
    b[i].time=2000;
    b[i].cost=0;
}

    for(i=1;i<=m;i++){
        int l,r,t,c;
       cin>>l>>r>>t>>c;
       for(j=l;j<=r;j++){
        if(b[j].time>t){
            b[j].cost=c;
            b[j].time=t;
        }
        if(b[j].time==t){
            b[j].cost=min(c,b[j].cost);
        }

       }

    }
    int ans=0;
for(i=1;i<=n;i++){
        ans=ans+b[i].cost;
}
cout<<ans<<endl;

}


#include<bits/stdc++.h>
using namespace std;

typedef struct {
int time;
int cost;
} bet;

int main(){
int n,m;
cin>>n>>m;
bet b[105];
int i,j,k;
for(i=1;i<=n;i++)
{
    b[i].time=2000;
    b[i].cost=0;
}

    for(i=1;i<=m;i++){
        int l,r,t,c;
       cin>>l>>r>>t>>c;
       for(j=l;j<=r;j++){
        if(b[j].time>t){
            b[j].cost=c;
            b[j].time=t;
        }
        else
        if(b[j].time==t){
            b[j].cost=max(c,b[j].cost);
        }

       }

    }
    int ans=0;
for(i=1;i<=n;i++){
        ans=ans+b[i].cost;
}
cout<<ans<<endl;

}


#include<bits/stdc++.h>
using namespace std;

typedef struct {
int time;
int cost;
} bet;

int main(){
int n,m;
cin>>n>>m;
bet b[105];
int i,j,k;
for(i=1;i<=n;i++)
{
    b[i].time=2000;
    b[i].cost=0;
}

    for(i=1;i<=m;i++){
        int l,r,t,c;
       cin>>l>>r>>t>>c;
       for(j=l;j<=r;j++){
        if(b[j].time>t)
            b[j].cost=c;
            b[j].time=t;
       }

    }
    int ans=0;
for(i=1;i<=n;i++){
        ans=ans+b[i].cost;
}
cout<<ans<<endl;

}


#include <bits/stdc++.h>

using namespace std;

int main()
{
	ios_base::sync_with_stdio(false);

	int n, m;
	cin >> n >> m;
	int mini[n+1], coin[n+1], l, r, t, c;
	memset(coin, 0, sizeof(coin));
	memset(mini, 2, sizeof(mini));

	for (int i = 0; i < m; ++i) {
		cin >> l >> r >> t >> c;
		for (int j = l; j <= r; ++j) {
			if (t < mini[j]) {
				mini[j] = t;
				coin[j] = c;
			}
		}
	}

	int ans = 0;
	for (int i = 1; i <= n; ++i)
		ans += coin[i];

	cout << ans << endl;

	return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
	ios_base::sync_with_stdio(false);

	int n, m;
	cin >> n >> m;
	int l[m], r[m], t[m], c[m], mini[n+1], coin[n+1];
	memset(coin, 0, sizeof(coin));
	for (int i = 0; i < n; ++i)
		mini[i] = 1000000;

	for (int i = 0; i < m; ++i) {
		cin >> l[i] >> r[i] >> t[i] >> c[i];
		for (int j = l[i]; j <= r[i]; ++j) {
			if (t[i] < mini[j]) {
				mini[j] = t[i];
				coin[j] = c[i];
			} else if (t[i] == mini[j]) {
				coin[j] = max(coin[j], c[i]);
			}
		}
	}

	int ans = 0;
	for (int i = 1; i <= n; ++i)
		ans += coin[i];

	cout << ans << endl;

	return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
	ios_base::sync_with_stdio(false);

	int n, m;
	cin >> n >> m;
	int l[m], r[m], t[m], c[m], mini[n+1], coin[n+1];
	memset(coin, 0, sizeof(coin));
	for (int i = 0; i < n; ++i)
		mini[i] = 1000000;

	for (int i = 0; i < m; ++i) {
		cin >> l[i] >> r[i] >> t[i] >> c[i];
		for (int j = l[i]; j <= r[i]; ++j) {
			if (t[i] < mini[j]) {
				mini[j] = t[i];
				coin[j] = c[i];
			}
		}
	}

	int ans = 0;
	for (int i = 1; i <= n; ++i)
		ans += coin[i];

	cout << ans << endl;

	return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n, m;
    cin >> n >> m;
    bool runs[101][101];
    memset(runs, 0, sizeof(runs));
    int time[m+1], profit[m+1];
    for(int i=1; i<=m; i++)
    {
        int a, b;
        cin >> a >> b >> time[i] >> profit[i];
        for(int j=a; j<=b; j++)
        {
            runs[i][j] = true;
        }
    }
    int res = 0;
    for(int i=1; i<=n; i++)
    {
        bool found = false;
        int mintime = 9999999;
        int id = -1;
        for(int j=1; j<=m; j++)
        {
            if(runs[j][i] == true)
            {
                found = true;
                if(mintime > time[j])
                {
                    id = j;
                    mintime = time[j];
                }

            }

        }
        if(found)
            res += profit[id];

    }
    cout << res << endl;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n, m;
    cin >> n >> m;
    bool runs[101][101];
    memset(runs, 0, sizeof(runs));
    int time[m+1], profit[m+1];
    for(int i=1; i<=m; i++)
    {
        int a, b;
        cin >> a >> b >> time[i] >> profit[i];
        for(int j=a; j<=b; j++)
        {
            runs[i][j] = true;
        }
    }
    int res = 0;
    for(int i=1; i<=n; i++)
    {
        bool found = false;
        int mintime = 9999999;
        int id = -1;
        for(int j=1; j<=m; j++)
        {
            if(runs[j][i] == true)
            {
                found = true;
                if(mintime > time[j])
                {
                    id = j;
                    mintime = time[j];
                }
                else if(mintime == time[j])
                {
                    if(profit[j] > profit[id])
                    {
                        id = j;
                    }
                }
            }

        }
        if(found)
            res += profit[id];

    }
    cout << res << endl;
    return 0;
}


#include<bits/stdc++.h>
#include<vector>
#include<algorithm>
using namespace std;
main(){
    int n,m,i,section=0,j,profit=0;
    vector<pair<int,int>>v;
    cin>>n>>m;
    int l[105],r[105],t[105],c[105],numS[105]={0};
    for(i=1;i<=m;i++){
        cin>>l[i]>>r[i]>>t[i]>>c[i];
        v.push_back(make_pair(t[i],i));
    }
    sort(v.begin(),v.end());
    for(auto itr=v.begin();itr!=v.end();itr++){
        i=(*itr).second;
        for(j=l[i];j<=r[i];j++){
            if(numS[j]==0) {profit+=c[i];numS[j]=1;section++;}
        }
    }
    cout<<profit<<endl;
    return 0;
}


#include<bits/stdc++.h>
#include<sstream>
#include<string>
#define lli  long long int
#define ll long long
#define ld long double
#define mod 1000000007
#define M 100006
#define pb push_back
#define ff first
#define ss second
#define all(v) v.begin(),v.end()
#define mp make_pair
#define br cout<<'\n';
#define f(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) f(i,0,n)
#define fd(i,a,b) for(int i=a;i>=b;i--)
#define sz(a) a.size()
#define pii pair< int,int >
#define pll pair< ll,ll >
#define vii vector<pii>
#define vii vector<pii>
#define viii vector<tri>
#define pqueue priority_queue< int >
#define flush fflush(stdout)
#define in(a,n) lli a[n];for(lli i=0;i<n;i++)cin>>a[i];
#define printv(v) for(vector<lli> :: iterator itv=v.begin();itv!=v.end();itv++)cout<<*itv<<' ';br
#define prints(s) for(set<lli> :: iterator its=s.begin();its!=s.end();its++)cout<<*its<<' ';br
#define print2(a,b) cout<<a<<' '<<b;br
#define print3(a,b,c) cout<<a<<' '<<b<<' '<<c;br
#define print4(a,b,c,d) cout<<a<<' '<<b<<' '<<c<<' '<<d;br
#define sum(a,n) lli sum=0;for(lli i=0;i<n;i++)sum+=a[i];
#define check cout<<"x"<<endl;
#define lower(a) transform(a.begin(),a.end(),a.begin(),::tolower);
#define upper(a) transform(a.begin(),a.end(),a.begin(),::toupper);

using namespace std;

lli modexp(lli a,lli n)
{
    lli r=1;
    while(n){
        if(n&1)
            r=(r*a)%mod;
        a=(a*a)%mod;
        n>>=1;
    }
    return r;
}

bool cmpfunc(const pair<int,int> &u,const pair<int,int> &v)

{
if(u.first<v.first)

 return true;

 return false;
}

bool compare(pair<lli, lli> p,pair<lli, lli >  q){
    if(p.ff < q.ff)
        return true ;
    else if(p.ff == q.ff)
    {
        if(p.ss < q.ss)
            return true ;
        return false ;
    }
        return false ;
}

lli w[1000000];
lli ans[1000000];

lli get(lli x)
{
    if(x == w[x])
        return x;
    return w[x] = get(w[x]);
}

void merge(lli a, lli b)
{
    a = get(a);
    b = get(b);
    if(a == b)
        return ;
    ans[a] += ans[b];
    w[b] = a;
}

lli a[1000];

void solve()
{

    rep(i, 1000)
    {
        a[i] = INT_MAX;
    }
    lli n, m;
    cin>>n>>m;
    lli p = 0;
    lli x[1000];
    rep(i, 1000)
    {
        x[i] = 1000000;
    }
    lli ans[1000];
    rep(i, m)
    {
        lli l, r, t, c;
        cin>>l>>r>>t>>c;
        f(j, l, r + 1){
            if(t < x[j])
            {
                x[j] = t;
                ans[j] = c;
            }
        }
    }

    f(i, 1, n + 1)
    {
        p += ans[i];
    }
    cout<<p;
    return ;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    lli t;
//    cin>>t;
    t=1;
    while(t--)
    {

        solve();
    }
    return 0;
}
/*
1
6
2 3 5 15 12 10
*/


#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#define N 120
#define M 120
using namespace std;

int a[N];
int l[M], r[M], t[M], c[M];

int main(void)
{
    int n, m;
    int i, j;
    int o;

    scanf("%d %d", &n, &m);
    for(i = 1; i <= m; i ++)
    {
        scanf("%d %d %d %d", &l[i], &r[i], &t[i], &c[i]);
        for(j = l[i]; j <= r[i]; j ++)
            if(!a[j] || t[i] < t[a[j]])
                a[j] = i;
    }

    for(i = 1, o = 0; i <= n; i ++)
        o += c[a[i]];

    printf("%d\n", o);

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

#ifdef ACMTUYO
struct RTC{~RTC(){cerr << "Time: " << clock() * 1.0 / CLOCKS_PER_SEC <<" seconds\n";}} runtimecount;
#define DBG(X) cerr << #X << " = " << X << '\n';
#else
struct RTC{};
#define DBG(X)
#endif

#define fast_io() ios_base::sync_with_stdio(false)
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
#define sz(x) ((int)(x).size())
#define all(c) (c).begin(),(c).end()
#define forn(i, n) for (int i = 0; i < (n); i++)
typedef long long int ll;
vector<set<pair<pair<int,int>,int> > > v;
int main() {
  int n,m,l,r,t,c;
  scanf("%d %d",&n,&m);
  v.resize(n+2);
  forn(j,m){
    scanf("%d %d %d %d",&l,&r,&t,&c);
    for(int i=l;i<=r;i++) {
      v[i].insert(mp(mp(t,j),c));
    }
  }
  ll sol=0;
  for(int i=1;i<=n;i++) {
    if(sz(v[i])==0)continue;
    int aux=v[i].begin()->second;
   // cout<<aux<<endl;
    sol+=aux;
  }
  printf("%lld\n",sol);
  return 0;
}


#include <bits/stdc++.h>

using namespace std;

#ifdef ACMTUYO
struct RTC{~RTC(){cerr << "Time: " << clock() * 1.0 / CLOCKS_PER_SEC <<" seconds\n";}} runtimecount;
#define DBG(X) cerr << #X << " = " << X << '\n';
#else
struct RTC{};
#define DBG(X)
#endif

#define fast_io() ios_base::sync_with_stdio(false)
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
#define sz(x) ((int)(x).size())
#define all(c) (c).begin(),(c).end()
#define forn(i, n) for (int i = 0; i < (n); i++)
typedef long long int ll;
vector<set<pair<int,int> > > v;
int main() {
  int n,m,l,r,t,c;
  scanf("%d %d",&n,&m);
  v.resize(n+2);
  forn(i,m){
    scanf("%d %d %d %d",&l,&r,&t,&c);
    for(int i=l;i<=r;i++) {
      v[i].insert(mp(t,c));
    }
  }
  ll sol=0;
  for(int i=1;i<=n;i++) {
    int aux=0;
    if(sz(v[i])==0)continue;
    for(auto it=v[i].begin();it!=v[i].end() and it->first==v[i].begin()->first;it++) {
      aux=it->second;
    }
    sol+=aux;
  }
  printf("%lld\n",sol);
  return 0;
}


#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include<set>
#include <cmath>
#include<sstream>
#include<queue>
#include<istream>
#include<vector>
#include<stdio.h>
#include<stack>
#include<deque>
#include<bitset>
#include<string>
#include<cstdio>
#include<map>
#include<iterator>
#include<iomanip>
#define prfs(x) printf("%s\n",x.c_str())
#define prfi(x) printf("%d\n",x);
#define sfi(X) scanf("%d",&X);
#define lop(i,n) for (int i = 0 ; i < n ;i++)
#define blop(i,n) for(int i = n-1 ; i>=0;i--)
#define M_P make_pair
#define All(X) (X).begin(),(X).end()
#define SZ(n) (int)(n).size()
#define voi vector<int>
#define Allr(X) (X).rbegin(),(X).rend()
#define vos vector<string>
#define vob vector<bool>
#define vovi vector<vector<int > >
#define vob vector<bool>
#define ll long long
using namespace std;
struct sportM {

	int Start;
	int End;
	int Time;
	int Profit;
	int Index;
	bool operator<(const sportM &other)const
	{
		if (Time != other.Time)
			return Time < other.Time;
			return Index > Index;
	}
	sportM() {}
	sportM(int s, int e, int t, int p,int i)
	{
		this->Start = s, this->End = e, this->Time = t, this->Profit = p, this->Index = i;
	}
};
vector<sportM> v;
int main()
{

	int N, M;scanf("%d%d", &N, &M);
	for (int i = 0; i < M; i++)
	{
		int a, b, c, d;scanf("%d%d%d%d", &a, &b, &c, &d);
		v.push_back(sportM(a, b, c, d,i));
	}
	sort(All(v));
	int Ans = 0;
	for (int section = 1 ; section <= N; section++)
	{
		for (int j = 0; j < v.size(); j++)
		{
			if (v[j].Start <= section && v[j].End >= section)
			{
				Ans += v[j].Profit;
				j = 10000;
			}
		}
	}
	printf("%d\n", Ans);

		return 0;
	}


#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include<set>
#include <cmath>
#include<sstream>
#include<queue>
#include<istream>
#include<vector>
#include<stdio.h>
#include<stack>
#include<deque>
#include<bitset>
#include<string>
#include<cstdio>
#include<map>
#include<iterator>
#include<iomanip>
#define prfs(x) printf("%s\n",x.c_str())
#define prfi(x) printf("%d\n",x);
#define sfi(X) scanf("%d",&X);
#define lop(i,n) for (int i = 0 ; i < n ;i++)
#define blop(i,n) for(int i = n-1 ; i>=0;i--)
#define M_P make_pair
#define All(X) (X).begin(),(X).end()
#define SZ(n) (int)(n).size()
#define voi vector<int>
#define Allr(X) (X).rbegin(),(X).rend()
#define vos vector<string>
#define vob vector<bool>
#define vovi vector<vector<int > >
#define vob vector<bool>
#define ll long long
using namespace std;
struct sportM {

	int Start;
	int End;
	int Time;
	int Profit;
	int Index;
	bool operator<(const sportM &other)const
	{
		if (Time != other.Time)
			return Time < other.Time;
			return Index < Index;
	}
	sportM() {}
	sportM(int s, int e, int t, int p,int i)
	{
		this->Start = s, this->End = e, this->Time = t, this->Profit = p, this->Index = i;
	}
};
vector<sportM> v;
int main()
{

	int N, M;scanf("%d%d", &N, &M);
	for (int i = 0; i < M; i++)
	{
		int a, b, c, d;scanf("%d%d%d%d", &a, &b, &c, &d);
		v.push_back(sportM(a, b, c, d,i));
	}
	sort(All(v));
	int Ans = 0;
	for (int section = 1 ; section <= N; section++)
	{
		for (int j = 0; j < v.size(); j++)
		{
			if (v[j].Start <= section && v[j].End >= section)
			{
				Ans += v[j].Profit;
				j = 10000;
			}
		}
	}
	printf("%d\n", Ans);

		return 0;
	}


#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include<set>
#include <cmath>
#include<sstream>
#include<queue>
#include<istream>
#include<vector>
#include<stdio.h>
#include<stack>
#include<deque>
#include<bitset>
#include<string>
#include<cstdio>
#include<map>
#include<iterator>
#include<iomanip>
#define prfs(x) printf("%s\n",x.c_str())
#define prfi(x) printf("%d\n",x);
#define sfi(X) scanf("%d",&X);
#define lop(i,n) for (int i = 0 ; i < n ;i++)
#define blop(i,n) for(int i = n-1 ; i>=0;i--)
#define M_P make_pair
#define All(X) (X).begin(),(X).end()
#define SZ(n) (int)(n).size()
#define voi vector<int>
#define Allr(X) (X).rbegin(),(X).rend()
#define vos vector<string>
#define vob vector<bool>
#define vovi vector<vector<int > >
#define vob vector<bool>
#define ll long long
using namespace std;
struct sportM {

	int Start;
	int End;
	int Time;
	int Profit;
	int Index;
	bool operator<(const sportM &other)const
	{
		if (Time != other.Time)
			return Time < other.Time;
			return Index < other.Index;
	}
	sportM() {}
	sportM(int s, int e, int t, int p,int i)
	{
		this->Start = s, this->End = e, this->Time = t, this->Profit = p, this->Index = i;
	}
};
vector<sportM> v;
int main()
{

	int N, M;scanf("%d%d", &N, &M);
	for (int i = 0; i < M; i++)
	{
		int a, b, c, d;scanf("%d%d%d%d", &a, &b, &c, &d);
		v.push_back(sportM(a, b, c, d,i));
	}
	sort(All(v));
	int Ans = 0;
	for (int section = 1 ; section <= N; section++)
	{
		for (int j = 0; j < v.size(); j++)
		{
			if (v[j].Start <= section && v[j].End >= section)
			{
				Ans += v[j].Profit;
				j = 10000;
			}
		}
	}
	printf("%d\n", Ans);

		return 0;
	}


#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include<set>
#include <cmath>
#include<sstream>
#include<queue>
#include<istream>
#include<vector>
#include<stdio.h>
#include<stack>
#include<deque>
#include<bitset>
#include<string>
#include<cstdio>
#include<map>
#include<iterator>
#include<iomanip>
#define prfs(x) printf("%s\n",x.c_str())
#define prfi(x) printf("%d\n",x);
#define sfi(X) scanf("%d",&X);
#define lop(i,n) for (int i = 0 ; i < n ;i++)
#define blop(i,n) for(int i = n-1 ; i>=0;i--)
#define M_P make_pair
#define All(X) (X).begin(),(X).end()
#define SZ(n) (int)(n).size()
#define voi vector<int>
#define Allr(X) (X).rbegin(),(X).rend()
#define vos vector<string>
#define vob vector<bool>
#define vovi vector<vector<int > >
#define vob vector<bool>
#define ll long long
using namespace std;
struct sportM {

	int Start;
	int End;
	int Time;
	int Profit;
	bool operator<(const sportM &other)const
	{
		if (Time != other.Time)
			return Time < other.Time;
		if (Profit != other.Profit)
			return Profit > other.Profit;
	}
	sportM() {}
	sportM(int s, int e, int t, int p)
	{
		this->Start = s, this->End = e, this->Time = t, this->Profit = p;
	}
};
vector<sportM> v;
int main()
{

	int N, M;scanf("%d%d", &N, &M);
	for (int i = 0; i < M; i++)
	{
		int a, b, c, d;scanf("%d%d%d%d", &a, &b, &c, &d);
		v.push_back(sportM(a, b, c, d));
	}
	sort(All(v));
	int Ans = 0;
	for (int section = 1 ; section <= N; section++)
	{
		for (int j = 0; j < v.size(); j++)
		{
			if (v[j].Start <= section && v[j].End >= section)
			{
				Ans += v[j].Profit;j = 10000;
			}
		}
	}
	printf("%d\n", Ans);

		return 0;
	}


#include <bits/stdc++.h>
#include <stdlib.h>
#define mp make_pair
using namespace std;
typedef long long int lli;
typedef unsigned long long int ulli;
typedef pair<int,int> pii;
typedef pair<lli,lli> pll;

struct A
{
	int start , finish;
	int time , coin;

	A() {}
	A( int s, int f , int t ,int c ) { start = s , finish = f , time = t , coin = c; }
} a[105];

int main()
{
	int n , m;
	cin>>n>>m;

	map< pair<int,int> , int > s;
	for ( int i=0 ; i<m ; i++ )
	{
		cin>>a[i].start>>a[i].finish>>a[i].time>>a[i].coin;
		s[ mp( a[i].start , 0 ) ] = i;
		s[ mp( a[i].finish , 1 ) ] = i;
	}
	a[101].coin = 0;

	set< pair<int,int> > p;
	int last = 0 , ans = 0;
	for ( map< pair<int,int> , int >::iterator i = s.begin() ; i != s.end() ; i++ )
	{
		int t = i->first.first , o = i->first.second , id = i->second;

		if ( o == 0 )
		{
			int dif = t - last - 1;
			last = t - 1;

			int winner = (p.size() ? p.begin()->second : 101);
			ans += a[winner].coin * dif;

			p.insert( mp( a[id].time , id ) );
		}
		else
		{
			int dif = t - last;
			last = t;

			int winner = (p.size() ? p.begin()->second : 101);
			ans += a[winner].coin * dif;

			p.erase( mp( a[id].time , id ) );
		}
	}

	cout<<ans<<"\n";

	return 0;
}


#include <bits/stdc++.h>
#include <stdlib.h>
#define mp make_pair
using namespace std;
typedef long long int lli;
typedef unsigned long long int ulli;
typedef pair<int,int> pii;
typedef pair<lli,lli> pll;

struct A
{
	int start , finish;
	int time , coin;

	A() {}
	A( int s, int f , int t ,int c ) { start = s , finish = f , time = t , coin = c; }
} a[105];

int main()
{
	int n , m;
	cin>>n>>m;

	multimap< pair<int,int> , int > s;
	for ( int i=0 ; i<m ; i++ )
	{
		cin>>a[i].start>>a[i].finish>>a[i].time>>a[i].coin;
		s.insert( mp( mp( a[i].start , 0 ) , i ) );
		s.insert( mp( mp( a[i].finish , 1 ) , i ) );
	}
	a[101].coin = 0;

	set< pair<int,int> > p;
	int last = 0 , ans = 0;
	for ( multimap< pair<int,int> , int >::iterator i = s.begin() ; i != s.end() ; i++ )
	{
		int t = i->first.first , o = i->first.second , id = i->second;

		if ( o == 0 )
		{
			int dif = t - last - 1;
			last = t - 1;

			int winner = (p.size() ? p.begin()->second : 101);
			ans += a[winner].coin * dif;

			p.insert( mp( a[id].time , id ) );
		}
		else
		{
			int dif = t - last;
			last = t;

			int winner = (p.size() ? p.begin()->second : 101);
			ans += a[winner].coin * dif;

			p.erase( mp( a[id].time , id ) );
		}
	}

	cout<<ans<<"\n";

	return 0;
}


#include <iostream>
#include <string.h>
using namespace std;
int main()
{
    int n , m , time[105] , p[105]{};
    int l , r , t , c , x = 0;
    cin >> n >> m;
    memset(time , 10000 , sizeof(time));
    for(int i = 0; i < m ; i++){
        cin >> l >> r >> t >> c;
        while(l <= r && t <= time[l])
            time[l] = t , p[l] = max(p[l] , c) , l++;
    }
    for(int i = 1 ; i <= n ; i++)
        x += p[i];
    cout << x << "\n";
    return 0;
}


#include <iostream>
#include <string.h>
using namespace std;
int main()
{
    int n , m , time[105] , p[105]{};
    int l , r , t , c , x = 0;
    cin >> n >> m;
    memset(time , 10000 , sizeof(time));
    for(int i = 1; i <= m ; i++){
        cin >> l >> r >> t >> c;
        for(int j = l ; j <= r ; j++)
            if(t < time[j])
                time[j] = t , p[j] = c;
    }
    for(int i = 1 ; i <= n ; i++)
        x += p[i];
    cout << x << "\n";
    return 0;
}


#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <string>
#include <cstring>
#include <cassert>
#include <stack>
#include <cstdlib>
#include <queue>
#include <set>
#include <map>
#include <cassert>
#include <sstream>
#include <cmath>
using namespace std;

void task();

int main() {
#ifdef LUNAWYLL
    freopen("input.txt", "r", stdin);
#endif
    task();
    return 0;
}

#ifdef LUNAWYLL
#define dbg(x) cout << #x << " = " << (x) << endl;
#define dbg2(a, b) cout << #a << " = " << (a) << "; "<<\
        #b << " = " << (b) << endl;
#else
#define dbg(...) (void(1));
#define dbg2(...) (void(1));
#endif

typedef long long int llint;
typedef vector<int> vi;
typedef pair<int, int> pii;
#define all(v) v.begin(), v.end()

const int N = (int)1e5 + 10;
const int MODULO = (int)1e9 + 3;
const int INF = (int)1e9;
const int BUF_SIZE = (int)1e5 + 10;

int n, m;
int tm[110], num[110], c[110];

void task(){
	scanf("%d %d", &n, &m);
	fill(tm, tm + 110, 1010);
	fill(num, num + 110, 100);
	for (int i = 0; i < n; ++i){
		int l, r, t;
		scanf("%d %d %d %d", &l, &r, &t, &c[i]);
		for (int j = l; j <= r; ++j){
			if (tm[j] > t){
				tm[j] = t;
				num[j] = i;
			} else if (tm[j] == t){
				if (c[num[j]] < c[i]){
					num[j] = i;
				}
			}
		}
	}
	int ans = 0;
	for (int i = 1; i <= n; ++i){
		ans += c[num[i]];
	}
	printf("%d", ans);
}


#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <string>
#include <cstring>
#include <cassert>
#include <stack>
#include <cstdlib>
#include <queue>
#include <set>
#include <map>
#include <cassert>
#include <sstream>
#include <cmath>
using namespace std;

void task();

int main() {
#ifdef LUNAWYLL
    freopen("input.txt", "r", stdin);
#endif
    task();
    return 0;
}

#ifdef LUNAWYLL
#define dbg(x) cout << #x << " = " << (x) << endl;
#define dbg2(a, b) cout << #a << " = " << (a) << "; "<<\
        #b << " = " << (b) << endl;
#else
#define dbg(...) (void(1));
#define dbg2(...) (void(1));
#endif

typedef long long int llint;
typedef vector<int> vi;
typedef pair<int, int> pii;
#define all(v) v.begin(), v.end()

const int N = (int)1e5 + 10;
const int MODULO = (int)1e9 + 3;
const int INF = (int)1e9;
const int BUF_SIZE = (int)1e5 + 10;

int n, m;
int tm[110], num[110], c[110];

void task(){
	scanf("%d %d", &n, &m);
	fill(tm, tm + 110, 1010);
	fill(num, num + 110, 101);
	for (int i = 0; i < n; ++i){
		int l, r, t;
		scanf("%d %d %d %d", &l, &r, &t, &c[i]);
		for (int j = l; j <= r; ++j){
			if (tm[j] > t){
				tm[j] = t;
				num[j] = i;
			} else if (tm[j] == t){
				if (num[j] > i){
					num[j] = i;
				}
			}
		}
	}
	int ans = 0;
	for (int i = 1; i <= n; ++i){
		ans += c[num[i]];
	}
	printf("%d", ans);
}


#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <string>
#include <cstring>
#include <cassert>
#include <stack>
#include <cstdlib>
#include <queue>
#include <set>
#include <map>
#include <cassert>
#include <sstream>
#include <cmath>
using namespace std;

void task();

int main() {
#ifdef LUNAWYLL
    freopen("input.txt", "r", stdin);
#endif
    task();
    return 0;
}

#ifdef LUNAWYLL
#define dbg(x) cout << #x << " = " << (x) << endl;
#define dbg2(a, b) cout << #a << " = " << (a) << "; "<<\
        #b << " = " << (b) << endl;
#else
#define dbg(...) (void(1));
#define dbg2(...) (void(1));
#endif

typedef long long int llint;
typedef vector<int> vi;
typedef pair<int, int> pii;
#define all(v) v.begin(), v.end()

const int N = (int)1e5 + 10;
const int MODULO = (int)1e9 + 3;
const int INF = (int)1e9;
const int BUF_SIZE = (int)1e5 + 10;

int n, m;
int tm[110], num[110], c[110];

void task(){
	scanf("%d %d", &n, &m);
	fill(tm, tm + 110, 1010);
	fill(num, num + 110, 101);
	for (int i = 0; i < m; ++i){
		int l, r, t;
		scanf("%d %d %d %d", &l, &r, &t, &c[i]);

		for (int j = l; j <= r; ++j){
			if (tm[j] > t){

				tm[j] = t;
				num[j] = i;
			} else if (tm[j] == t){
				if (num[j] > i){
					num[j] = i;
				}
			}
		}
	}
	int ans = 0;
	for (int i = 1; i <= n; ++i){
		ans += c[num[i]];
	}
	printf("%d", ans);
}


#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <string>
#include <cstring>
#include <cassert>
#include <stack>
#include <cstdlib>
#include <queue>
#include <set>
#include <map>
#include <cassert>
#include <sstream>
#include <cmath>
using namespace std;

void task();

int main() {
#ifdef LUNAWYLL
    freopen("input.txt", "r", stdin);
#endif
    task();
    return 0;
}

#ifdef LUNAWYLL
#define dbg(x) cout << #x << " = " << (x) << endl;
#define dbg2(a, b) cout << #a << " = " << (a) << "; "<<\
        #b << " = " << (b) << endl;
#else
#define dbg(...) (void(1));
#define dbg2(...) (void(1));
#endif

typedef long long int llint;
typedef vector<int> vi;
typedef pair<int, int> pii;
#define all(v) v.begin(), v.end()

const int N = (int)1e5 + 10;
const int MODULO = (int)1e9 + 3;
const int INF = (int)1e9;
const int BUF_SIZE = (int)1e5 + 10;

int n, m;
int tm[110], num[110], c[110];

void task(){
	scanf("%d %d", &n, &m);
	fill(tm, tm + 110, 1010);
	fill(num, num + 110, 100);
	for (int i = 0; i < n; ++i){
		int l, r, t;
		scanf("%d %d %d %d", &l, &r, &t, &c[i]);
		for (int j = l; j <= r; ++j){
			if (tm[j] > t){
				tm[j] = t;
				num[j] = i;
			} else if (tm[j] == t){
				if (num[j] > i){
					num[j] = i;
				}
			}
		}
	}
	int ans = 0;
	for (int i = 1; i <= n; ++i){
		ans += c[num[i]];
	}
	printf("%d", ans);
}


#include<iostream>
using namespace std;
int k[109],p[109],l,r,t,c,n,m,ans;
main()
{cin>>n>>m;
for (int i=0; i<m; i++)
{cin>>l>>r>>t>>c;
for (int j=l; j<=r; j++)
{if(t<k[j] || k[j]==0)
{k[j]=t;  ans-=p[j]; p[j]=c; ans+=p[j];}}
}

cout<<ans<<endl;
}


#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
using namespace std;
typedef	long long ll;
typedef unsigned long long ull;
#define all(v) ((v).begin()),((v).end())
#define sz(v) ((int)((v).size()))
#define PI(n) ((double)acos(n))
#define pw2(n) (1LL<<(n))
#define sfi1(v) scanf("%d",&v)
#define sfi2(v1,v2) scanf("%d%d",&v1,&v2)
#define sfi3(v1,v2,v3) scanf("%d %d %d",&v1,&v2,&v3)
int dx8[8] = { 1, -1, 0, 0, 1, 1, -1, -1 };
int dy8[8] = { 0, 0, 1, -1, 1, -1, 1, -1 };
void file()
{
#ifndef ONLINE_JUDGE
	freopen("in.txt", "r", stdin);
	//freopen("out.txt", "w", stdout);
#else
	// online submission
#endif
}
void fast()
{
	std::ios_base::sync_with_stdio(0);
	cin.tie(NULL); cout.tie(NULL);
}
int main()
{

	int n, m;
	cin >> n >> m;
	int l[101], r[101], t[101],c[101];
	for (int i = 0; i < m; i++){
		cin >> l[i] >> r[i] >> t[i] >> c[i];
	}
	int ans = 0;
	for (int i = 1; i <= n; i++){
		int mn = 1e9,c1=0;
		for (int j = 0; j < m; j++){
			if (i >= l[j] && i <= r[j] && t[j]< mn){
				mn = t[j];
				c1 = c[j];
			}
		}
		if (mn != 1e9)

			ans += c1;
	}
	cout << ans << endl;
}


#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
using namespace std;
typedef	long long ll;
typedef unsigned long long ull;
#define all(v) ((v).begin()),((v).end())
#define sz(v) ((int)((v).size()))
#define PI(n) ((double)acos(n))
#define pw2(n) (1LL<<(n))
#define sfi1(v) scanf("%d",&v)
#define sfi2(v1,v2) scanf("%d%d",&v1,&v2)
#define sfi3(v1,v2,v3) scanf("%d %d %d",&v1,&v2,&v3)
int dx8[8] = { 1, -1, 0, 0, 1, 1, -1, -1 };
int dy8[8] = { 0, 0, 1, -1, 1, -1, 1, -1 };
void file()
{
#ifndef ONLINE_JUDGE
	freopen("in.txt", "r", stdin);
	//freopen("out.txt", "w", stdout);
#else
	// online submission
#endif
}
void fast()
{
	std::ios_base::sync_with_stdio(0);
	cin.tie(NULL); cout.tie(NULL);
}
int main()
{

	int n, m;
	cin >> n >> m;
	int l[101], r[101], t[101],c[101];
	for (int i = 0; i < m; i++){
		cin >> l[i] >> r[i] >> t[i] >> c[i];
	}
	int ans = 0;
	for (int i = 1; i <= n; i++){
		int mn = 500,c1=0;
		for (int j = 0; j < m; j++){
			if (i >= l[j] && i <= r[j] && t[j]< mn){
				mn = t[j];
				c1 = c[j];
			}
		}
		if (mn != 500)
			ans += c1;
	}
	cout << ans << endl;
}


#include <bits/stdc++.h>
#include <ext/numeric>
using namespace std;
using namespace __gnu_cxx;

#define sz(x) (int)x.size()

int n,m,ans;

struct p{
    int l,r,t,c;
};

p arr[111];

int main() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "rt", stdin);
#endif
    cin>>n>>m;
    for(int i=0;i<n;i++)
        cin>>arr[i].l>>arr[i].r>>arr[i].t>>arr[i].c;
    for(int i=1;i<1001;i++){
        int mnt=55555;
        for(int j=0;j<n;j++)
            if(arr[j].l<=i&&arr[j].r>=i)
                mnt=min(mnt,arr[j].t);
        if(mnt<55555){
            for(int j=0;j<n;j++)
                if(arr[j].l<=i&&arr[j].r>=i&&arr[j].t==mnt){
                    ans+=arr[j].c;
                    break;
                }
        }
    }
    cout<<ans;
}


#include <bits/stdc++.h>
#include <ext/numeric>
using namespace std;
using namespace __gnu_cxx;

#define sz(x) (int)x.size()

int n,m,ans;

struct p{
    int l,r,t,c;
};

p arr[111];

int main() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "rt", stdin);
#endif
    cin>>n>>m;
    for(int i=0;i<m;i++)
        cin>>arr[i].l>>arr[i].r>>arr[i].t>>arr[i].c;
    for(int i=1;i<=n;i++){
        int mnt=55555;
        for(int j=0;j<m;j++)
            if(arr[j].l<=i&&arr[j].r>=i)
                mnt=min(mnt,arr[j].t);
        if(mnt<55555){
            for(int j=0;j<m;j++)
                if(arr[j].l<=i&&arr[j].r>=i&&arr[j].t==mnt){
                    ans+=arr[j].c;
                    break;
                }
        }
    }
    cout<<ans;
}


#include <bits/stdc++.h>
using namespace std;
typedef struct
{
	int l,r,t,c;
}player;
int main()
{
	int n,m;
	cin>>n>>m;
	player a[m];
	for (int i=0;i<m;i++)
			cin>>a[i].l>>a[i].r>>a[i].t>>a[i].c;
	int count=0;
	int total=0;
	for (int i=1;i<=n;i++)
	{
		int min;
		int min_p=0;
		count=0;
		for (int j=0;j<m;j++)
		{
			if (i>=a[j].l&&i<=a[j].r)
			{
				if (count==0)
				{
					min=a[j].t;
					min_p=a[j].c;
					count++;
				}
				else
				{
					if (a[j].t<min)
					{
						min=a[j].t;
						min_p=a[j].c;
					}
				}
			}
		}
		//cout<<min_p<<endl;
		total+=min_p;
	}
	cout<<total;
}


#include <bits/stdc++.h>

using namespace std;

int main() {

    // freopen ("input", "r", stdin);
    // freopen ("output", "w", stdout);

    int n, m, res = 0;
    cin >> n >> m;
    vector<int> l(m), r(m), t(m), c(m);
    for (int i = 0; i < m; i++) cin >> l[i] >> r[i] >> t[i] >> c[i];
    for (int i = 1; i <= n; i++) {
        int winner = 0, winningTime = INT_MAX, winningPrize = 0;
        for (int j = 0; j < m; j++) {
            if (i >= l[j] && i <= r[j]) {
                if (winningTime > t[j]) {
                    winningPrize = c[j];
                    winningTime = t[j];
                    winner = j;
                }
            }
        }
        // cout << winner << endl;
        res += winningPrize;
    }
    cout << res;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
    int n, m;
    cin >> n >> m;
    vector<vector<int>> vec(m);
    for(int i = 0; i < m; i++) {
        int l, r, t, c;
        cin >> l >> r >> t >> c;
        vec[i].push_back(l);
        vec[i].push_back(r);
        vec[i].push_back(t);
        vec[i].push_back(c);
    }
    int sum = 0;
    for(int i = 1; i <= n; i++) {
        int t_min = 1001, c = 0;
        for(int j = 0; j < m; j++) {
            if(i>=vec[j][0] && i<=vec[j][1]) {
                if(vec[j][2]<t_min) {
                    t_min = vec[j][2];
                    c = vec[j][3];
                }
            }
        }
        sum += c;
    }
    cout << sum;
    return 0;
}


#include"bits/stdc++.h"
using namespace std;
#define int int64_t
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n,m;cin>>n>>m;
    pair<int,int> ar[110];
    for(int i=0;i<=100;i++)
        ar[i].first=1100,ar[i].second=0;
    for(int i=0;i<m;i++)
    {
        int l,r,t,c;cin>>l>>r>>t>>c;
        for(int j=l;j<=r;j++)
        {
            if(ar[j].first>t)
            {
                ar[j].first=t;
                ar[j].second=c;
            }
            else if(ar[j].first==t)
            {
                ar[j].second=max(c,ar[j].second);
            }
        }
    }
    int ans=0;
    for(int i=0;i<=100;i++)
        ans+=ar[i].second;
    cout<<ans<<"\n";
    return 0;
}


#include"bits/stdc++.h"
using namespace std;
#define int int64_t
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n,m;cin>>n>>m;
    pair<int,int> ar[110];
    for(int i=0;i<=100;i++)
        ar[i].first=1100,ar[i].second=0;
    for(int i=0;i<m;i++)
    {
        int l,r,t,c;cin>>l>>r>>t>>c;
        for(int j=l;j<=r;j++)
        {
            if(ar[j].first>t)
            {
                ar[j].first=t;
                ar[j].second=c;
            }
        }
    }
    int ans=0;
    for(int i=0;i<=100;i++)
        ans+=ar[i].second;
    cout<<ans<<"\n";
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int l[1000];
int r[1000];
int t[1000];
int c[1000];

int main(){
    int n, m;
    cin >> n >> m;
    for(int i = 0; i < m; i++){
        cin >> l[i] >> r[i] >> t[i] >> c[i];
    }
    int ans = 0;

    for(int i = 1; i <= n; i++){
        int minT = 1001;
        int y = -1;
        for(int j = 0; j < m; j++){
            if(l[j] <= i and i <= r[j] and minT > t[j]){
                y = j;
                minT = t[j];
            }
        }
        if(y != -1) ans += c[y];
    }
    cout << ans;
    return 0;
}


#include <bits/stdc++.h>
#define MAX 150
#define INF 1000000

using namespace std;

struct Comp{
	int t,c;
};

Comp section[MAX];
int n, m, l, r, t, c, som;

int main(){

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

	cin >> n >> m;

	for(int i = 1; i <= n; i++){
		section[i].t = INF;
		section[i].c = 0;
	}

	for(int i = 0; i < m; i++){
		cin >> l >> r >> t >> c;
		for(int j = l; j <= r; j++){
			if(t < section[j].t){
				section[j].c = c;
				section[j].t = t;
			}
		}
	}

	som = 0;
	for(int i = 1; i <= n; i++){
		som += section[i].c;
	}

	cout << som << "\n";

    return 0;
}


#include <bits/stdc++.h>
#define MAX 150
#define INF 1000000

using namespace std;

struct Comp{
	int t,c;
};

Comp section[MAX];
int n, m, l, r, t, c, som;

int main(){

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

	cin >> n >> m;

	for(int i = 1; i <= n; i++){
		section[i].t = INF;
		section[i].c = 0;
	}

	for(int i = 0; i < m; i++){
		cin >> l >> r >> t >> c;
		for(int j = l; j <= r; j++){
			if(t < section[j].t){
				section[j].c = c;
				section[j].t = t;
			}else if(t == section[j].t){
				section[j].c = max(section[j].c,c);
			}
		}
	}

	som = 0;
	for(int i = 1; i <= n; i++){
		som += section[i].c;
	}

	cout << som << "\n";

    return 0;
}


/* Author haleyk10198 */
/* �@��:  haleyk10198 */
#include <iostream>
#include <fstream>
#include <sstream>
#include <cstdlib>
#include <cstdio>
#include <vector>
#include <map>
#include <queue>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <iomanip>
#include <ctime>
#include <string>
#include <set>
#include <stack>

#define MOD 1000000007
#define INF 2147483647
#define PI 3.1415926535897932384626433
#define ll long long
#define pii pair<int,int>
#define mp(x,y) make_pair((x),(y))

using namespace std;

struct man{
	int l,r,t,g,ind;
	man(int a,int b,int c,int d,int e):l(a),r(b),t(c),g(d),ind(e){
	}
};

struct Custom{
	bool operator()(man a,man b){
		return a.t<b.t||(a.t==b.t&&a.ind<b.ind);
	}
};

int main(){
	//ios_base::sync_with_stdio(false);
	vector<man> arr;
	int n,m,res=0;
	cin>>n>>m;
	for(int i=0;i<m;i++){
		int a,b,c,d;
		cin>>a>>b>>c>>d;
		arr.push_back(man(a,b,c,d,i));
	}
	sort(arr.begin(),arr.end(),Custom());
	for(int i=1;i<=n;i++){
		for(auto x:arr){
			if(x.l<=i&&x.r>=i){
				res+=x.g;
				break;
			}
		}
	}
	cout<<res<<endl;
	return 0;
}


/* Author haleyk10198 */
/* �@��:  haleyk10198 */
#include <iostream>
#include <fstream>
#include <sstream>
#include <cstdlib>
#include <cstdio>
#include <vector>
#include <map>
#include <queue>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <iomanip>
#include <ctime>
#include <string>
#include <set>
#include <stack>

#define MOD 1000000007
#define INF 2147483647
#define PI 3.1415926535897932384626433
#define ll long long
#define pii pair<int,int>
#define mp(x,y) make_pair((x),(y))

using namespace std;

struct man{
	int l,r,t,g;
	man(int a,int b,int c,int d):l(a),r(b),t(c),g(d){
	}
};

struct Custom{
	bool operator()(man a,man b){
		return a.t<b.t||(a.t==b.t&&a.g>b.g);
	}
};

int main(){
	//ios_base::sync_with_stdio(false);
	vector<man> arr;
	int n,m,res=0;
	cin>>n>>m;
	for(int i=0;i<m;i++){
		int a,b,c,d;
		cin>>a>>b>>c>>d;
		arr.push_back(man(a,b,c,d));
	}
	sort(arr.begin(),arr.end(),Custom());
	for(int i=1;i<=n;i++){
		for(auto x:arr){
			if(x.l<=i&&x.r>=i){
				res+=x.g;
				break;
			}
		}
	}
	cout<<res<<endl;
	return 0;
}


#include <iostream>
using namespace std;
struct Node
{
	int li,ri,ti,ci;
};
int main(int argc,char**argv)
{
	int ans=0;
	int n,m;
	cin>>n>>m;
	Node *a=new Node[101];
	for(int i=0;i<m;i++)
	{
		cin>>a[i].li>>a[i].ri>>a[i].ti>>a[i].ci;
	}
	for(int i=1;i<=n;i++)
	{
		int mn_time=-1;
		for(int j=0;j<m;j++)
		{
			if(a[j].li<=i&&i<=a[j].ri)
			{
				if(mn_time==-1)
				mn_time=j;
				else if(a[j].ti<a[mn_time].ti)
				mn_time=j;
			}
		}
	 ans+=(mn_time!=-1)?a[mn_time].ci:0;
	}
	cout<<ans;
	return 0;
}


#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>

using namespace std;

vector<int> v_plaet(100000 + 1);
bool visted[100001];

int main()
{
	int n, m;
	//ifstream ff("file.txt");
	cin >> n >> m;
	vector <pair<int, int>> v_answer(100000 + 1);
	fill(v_answer.begin(), v_answer.end(), make_pair(INT_MAX, INT_MAX));
	for (int i = 1; m--; i++)
	{
		int l, r, t, c;
		//ff >> l >> r >> t >> c;
		scanf("%d%d%d%d", &l, &r, &t, &c);
		v_plaet[i] = c;
		for (int j = l; j <= r; j++)
		{
			visted[j] = true;
			if (v_answer[j].first > t)
			{
				v_answer[j].first = t;
				v_answer[j].second = i;
			}
		}
	}
	unsigned int sum = 0;
	for (int i = 1; i <=n; i++)
	{
		if (visted[i] == true)
		{
			sum += v_plaet[v_answer[i].second];
		}

	}

	cout << sum << endl;

	return 0;
}


/// ///////////////////// ///
///                       ///
///      Tamanna_24       ///
///                       ///
///         JU            ///
///                       ///
/// ///////////////////// ///

#include<iostream>
#include<sstream>
#include<cstring>
#include<cstdio>
#include<string>
#include<cmath>
#include<set>
#include<map>
#include<vector>
#include<queue>
#include<stack>
#include<algorithm>
#include<cstdlib>
#include<cctype>

typedef long long ll;
typedef unsigned long long ull;

#define pi 2.0*acos(0.0)

template <class T> T _diff(T a,T b) {return (a<b?b-a:a-b);}
template <class T> T _abs(T a) {return(a<0?-a:a);}
template <class T> T _max(T a, T b) {return (a>b?a:b);}
template <class T> T _min(T a, T b) {return (a<b?a:b);}
template <class T> T max3(T a, T b, T c) {return (_max(a,b)>c ? _max(a,b) : c);}
template <class T> T min3(T a, T b, T c) {return (_min(a,b)<c ? _min(a,b) : c);}
template< class T>T GCD(T a,T b) {
    a=_abs(a);b=_abs(b);T tmp;while(a%b){ tmp=a%b; a=b; b=tmp; } return b;
}
template< class T>T LCM(T a,T b) {
    a=_abs(a);b=_abs(b);return (a/GCD(a,b))*b;
}
template<class T> T toRad(T deg) { return (deg*pi)/(180.0) ;}
template<class T> T toDeg(T rad) { return (rad*180.0)/(pi) ;}

#define pb(a) push_back(a)
#define SET(a) memset(a,-1,sizeof(a))
#define CLR(a) memset(a,0,sizeof(a))
#define S(a) scanf("%d",&a)
#define P(a) printf("%d",a)
#define PN() puts("")
#define PCASE() printf("Case %d: ",kk++)
#define eps 1e-9
#define inf 2000000000
#define mod 1000000007
#define MX  1000000
using namespace std;

bool vis[100005];
int n;

int main()
{
    cin>>n;
    CLR(vis);
    int cnt =0, res=0, x;
    for(int i=0;i<2*n;i++){
        cin>>x;
        if(vis[x]) {
            cnt--;
            vis[x] = 0;
        }
        else {
            vis[x] = 1;
            cnt++;
        }
        res = max(res , cnt);
    }
    cout<<res<<endl;
return 0;
}


/// ///////////////////// ///
///                       ///
///      Tamanna_24       ///
///                       ///
///         JU            ///
///                       ///
/// ///////////////////// ///

#include<iostream>
#include<sstream>
#include<cstring>
#include<cstdio>
#include<string>
#include<cmath>
#include<set>
#include<map>
#include<vector>
#include<queue>
#include<stack>
#include<algorithm>
#include<cstdlib>
#include<cctype>

typedef long long ll;
typedef unsigned long long ull;

#define pi 2.0*acos(0.0)

template <class T> T _diff(T a,T b) {return (a<b?b-a:a-b);}
template <class T> T _abs(T a) {return(a<0?-a:a);}
template <class T> T _max(T a, T b) {return (a>b?a:b);}
template <class T> T _min(T a, T b) {return (a<b?a:b);}
template <class T> T max3(T a, T b, T c) {return (_max(a,b)>c ? _max(a,b) : c);}
template <class T> T min3(T a, T b, T c) {return (_min(a,b)<c ? _min(a,b) : c);}
template< class T>T GCD(T a,T b) {
    a=_abs(a);b=_abs(b);T tmp;while(a%b){ tmp=a%b; a=b; b=tmp; } return b;
}
template< class T>T LCM(T a,T b) {
    a=_abs(a);b=_abs(b);return (a/GCD(a,b))*b;
}
template<class T> T toRad(T deg) { return (deg*pi)/(180.0) ;}
template<class T> T toDeg(T rad) { return (rad*180.0)/(pi) ;}

#define pb(a) push_back(a)
#define SET(a) memset(a,-1,sizeof(a))
#define CLR(a) memset(a,0,sizeof(a))
#define S(a) scanf("%d",&a)
#define P(a) printf("%d",a)
#define PN() puts("")
#define PCASE() printf("Case %d: ",kk++)
#define eps 1e-9
#define inf 2000000000
#define mod 1000000007
#define MX  1000000
using namespace std;

bool vis[100005];
int n;

int main()
{
    cin>>n;
    CLR(vis);
    int cnt =0, res=0,x;
    for(int i=0;i<n;i++){
        cin>>x;
        if(vis[x]) cnt--;
        else {
            vis[x] = 1;
            cnt++;
        }
        res = max(res , cnt);
    }
    cout<<res<<endl;
return 0;
}


/// ///////////////////// ///
///                       ///
///      Tamanna_24       ///
///                       ///
///         JU            ///
///                       ///
/// ///////////////////// ///

#include<iostream>
#include<sstream>
#include<cstring>
#include<cstdio>
#include<string>
#include<cmath>
#include<set>
#include<map>
#include<vector>
#include<queue>
#include<stack>
#include<algorithm>
#include<cstdlib>
#include<cctype>

typedef long long ll;
typedef unsigned long long ull;

#define pi 2.0*acos(0.0)

template <class T> T _diff(T a,T b) {return (a<b?b-a:a-b);}
template <class T> T _abs(T a) {return(a<0?-a:a);}
template <class T> T _max(T a, T b) {return (a>b?a:b);}
template <class T> T _min(T a, T b) {return (a<b?a:b);}
template <class T> T max3(T a, T b, T c) {return (_max(a,b)>c ? _max(a,b) : c);}
template <class T> T min3(T a, T b, T c) {return (_min(a,b)<c ? _min(a,b) : c);}
template< class T>T GCD(T a,T b) {
    a=_abs(a);b=_abs(b);T tmp;while(a%b){ tmp=a%b; a=b; b=tmp; } return b;
}
template< class T>T LCM(T a,T b) {
    a=_abs(a);b=_abs(b);return (a/GCD(a,b))*b;
}
template<class T> T toRad(T deg) { return (deg*pi)/(180.0) ;}
template<class T> T toDeg(T rad) { return (rad*180.0)/(pi) ;}

#define pb(a) push_back(a)
#define SET(a) memset(a,-1,sizeof(a))
#define CLR(a) memset(a,0,sizeof(a))
#define S(a) scanf("%d",&a)
#define P(a) printf("%d",a)
#define PN() puts("")
#define PCASE() printf("Case %d: ",kk++)
#define eps 1e-9
#define inf 2000000000
#define mod 1000000007
#define MX  1000000
using namespace std;

bool vis[100005];
int n;

int main()
{
    cin>>n;
    CLR(vis);
    int cnt =0, res=0, x;
    for(int i=0;i<n;i++){
        cin>>x;
        if(vis[x]) {
            cnt--;
            vis[x] = 0;
        }
        else {
            vis[x] = 1;
            cnt++;
        }
        res = max(res , cnt);
    }
    cout<<res<<endl;
return 0;
}


#include<bits/stdc++.h>
using namespace std;
int a[200002],b[200002];
int main(){
	int n;
	cin>>n;
	for(int i=0;i<n*2;i++){
		cin>>a[i];
	}
	int ans=0;
	int x=0;
	for(int i=0;i<n*2;i++){
		b[a[i]]++;
		x=max(x,a[i]);
		int sum=0;
		for(int g=0;g<x+1;g++){
			if(b[g]==1){
				sum++;
			}
		}
		ans=max(sum,ans);
	}
	cout<<ans;
}


#include<bits/stdc++.h>
using namespace std;
int a[100001];
vector<int >v;
int main(){
	int n;
	cin>>n;
	for(int i=0;i<n*2;i++){
		cin>>a[i];
	}
	int ans=0;
	for(int i=0;i<n*2;i++){
			int t=v.size();
		ans=max(ans,t);
		bool ok=0;
		for(int g=0;g<v.size();g++){
			if(v[g]==a[i]){
				ok=1;
				v[g]=0;
				sort(v.begin(),v.end());
				reverse(v.begin(),v.end());
				v.pop_back();
			}
		}
		if(ok==0){
			v.push_back(a[i]);
		}

	}
	cout<<ans;
}


#include<bits/stdc++.h>
using namespace std;
int a[100001];
int main(){
	int n,maxs=0,ans=0;
	cin>>n;
	for(int i=0;i<n*2;i++){
		int t;
		cin>>t;
		a[t]++;
		if(a[t]==1){
			ans++;
		}
		else{
			ans--;
		}
		maxs=max(maxs,ans);
	}
	cout<<maxs;
}


#include<bits/stdc++.h>
using namespace std;
int a[200002],b[200002];
int main(){
	int n;
	cin>>n;
	for(int i=0;i<n*2;i++){
		cin>>a[i];
	}
	int ans=0;
	for(int i=0;i<n*2;i++){
		b[a[i]]++;
		int sum=0;
		for(int g=0;g<n*2;g++){
			if(b[g]==1){
				sum++;
			}
		}
		ans=max(sum,ans);
	}
	cout<<ans;
}


#include<bits/stdc++.h>
using namespace std;
int a[200002];
vector<int >v;
int main(){
	int n;
	cin>>n;
	for(int i=0;i<n*2;i++){
		cin>>a[i];
	}
	int ans=0;
	for(int i=0;i<n*2;i++){
			int t=v.size();
		ans=max(ans,t);
		bool ok=0;
		for(int g=0;g<v.size();g++){
			if(v[g]==a[i]){
				ok=1;
				v[g]=0;
				sort(v.begin(),v.end());
				reverse(v.begin(),v.end());
				v.pop_back();
			}
		}
		if(ok==0){
			v.push_back(a[i]);
		}

	}
	cout<<ans;
}


#include<bits/stdc++.h>

using namespace std;

#define fast   ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)

int main()
{
    fast;
    long n;
    cin >> n;
    set <long> S;
    long k=0,j,ma=0;
    for (int i=0; i<n; i++)
    {
        cin >> j;
        if(S.find(j)==S.end())
        {
            S.insert(j);
            k++;
            if (k>ma)ma=k;
        }
        if(S.find(j)!=S.end())
        {
            k--;
        }
    }
    cout << ma;
    return 0;
}


#include<bits/stdc++.h>

using namespace std;

#define fast   ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)

int main()
{
    fast;
    long long n;
    cin >> n;
    set <long long> S;
    long long k=0,j,ma=0;
    for (long long i=0; i<2*n; i++)
    {
        cin >> j;
        if(S.find(j)==S.end())
        {
            S.insert(j);
            k++;
            if (k>ma)ma=k;
        }
        else
        {
            k--;
        }
    }
    cout << ma;
    return 0;
}


#include<bits/stdc++.h>

using namespace std;

#define fast   ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)

int main()
{
    fast;
    long long n;
    cin >> n;
    set <long long> S;
    long long k=0,j,ma=0;
    for (long long i=0; i<n; i++)
    {
        cin >> j;
        if(S.find(j)==S.end())
        {
            S.insert(j);
            k++;
            if (k>ma)ma=k;
        }
        else
        {
            k--;
        }
    }
    cout << ma;
    return 0;
}


#include<bits/stdc++.h>

using namespace std;

#define fast   ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)

int main()
{
    //fast;
    long long n;
    cin >> n;
    set <long long> S;
    long long k=0,j,ma=0;
    for (long long i=0; i<2*n; i++)
    {
        cin >> j;
        if(S.find(j)==S.end())
        {
            S.insert(j);
            k++;
            if (k>ma)ma=k;
        }
        else
        {
            k--;
        }
    }
    cout << ma;
    return 0;
}


#include<bits/stdc++.h>

using namespace std;

#define fast   ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)

int main()
{
    fast;
    long n;
    cin >> n;
    set <long> S;
    long k=0,j,ma=0;
    for (int i=0; i<n; i++)
    {
        cin >> j;
        if(S.find(j)==S.end())
        {
            S.insert(j);
            k++;
            if (k>ma)ma=k;
        }
        else
        {
            k--;
        }
    }
    cout << ma;
    return 0;
}