#include <stdio.h>
int main()
{
int m, n;
scanf("%d %d", &m, &n);
int time[m];
for (int i = 0; i < m; i++)
time[i] = 1;
int sum[m];
for (int i = 0; i < m; i++)
sum[i] = 0;
long int rst[m];
int min, max, chs, num;
for (int i = 0; i < n; i++)
{
scanf("%d %d %d %d", &min, &max, &chs, &num);
switch (chs)
{
case 1:
for (int j = (min - 1); j < max; j++)
{
sum[j] += num;
}
break;
case 2:
for (int j = (min - 1); j < max; j++)
{
time[j] *= num;
}
break;
}
}
long int rstmax = 0;
for (int i = 0; i < m; i++)
{
rst[i] = time[i] * sum[i];
if (rst[i] > rstmax)
rstmax = rst[i];
}
for (int i = 0; i < m; i++)
{
if (rst[i] == rstmax)
{
printf("%d %ld", ++i, rstmax);
break;
}
}
return 0;
}