#include<bits/stdc++.h>
#define ll long long
#define N (int)1e5+1
using namespace std;
struct node{
ll a,b,c,d;
bool operator < (const node &A) {
if(a!=A.a) return a<A.a;
return b<A.b;
}
};
node p[N];
int T,n,ans2;
bool cheak(int x){
for(int i=1;i<=n;i++)
if(x<p[i].a) return false;
else x+=p[i].c;
return true;
}
bool cheak2(int x){
for(int i=1;i<=n;i++)
if(x<p[i].b) return false;
else x+=p[i].d;
return true;
}
int main(){
cin>>T>>n;
for(int i=1;i<=n;i++){
cin>>p[i].a>>p[i].b>>p[i].c>>p[i].d;
}
sort(p+1,p+n+1);
int L=0,R=1e9+1;
while(L+1<R){
int mid=(L+R)>>1;
if(cheak(mid)) R=mid;
else L=mid;
}
if(L==0) printf("0 ");
else printf("%d ",R);
L=0,R=1e9+1;
while(L+1<R){
int mid=(L+R)>>1;
if(cheak2(mid)) R=mid;
else L=mid;
}
if(L==0) printf("0\n");
else printf("%d\n",R);
}