import java.util.*; class C{ static Scanner s=new Scanner(System.in); static Stage stage; static LinkedList> events = new LinkedList>(); static boolean[] updated; static int updatedcount; public static void main(String[] args){ stage = new Stage(s.nextInt()); LinkedList finalevents; { LinkedList list = new LinkedList(); int l = s.nextInt(); for(int i=0;i(); } } finalevents=list; } updated = new boolean[stage.stage.length]; for(LinkedList l:events) { Event bonus_e = l.removeFirst(); paint(l); stage.addBonus(bonus_e.l, bonus_e.r); } if(!finalevents.isEmpty()) paint(finalevents); stage.finish(); System.out.print(stage.scoreA); System.out.print(" "); System.out.println(stage.scoreB); } static void paint(LinkedList l) { updatedcount = stage.stage.length; Arrays.fill(updated, false); for(Event e:l) { for(int i=e.l;i<=e.r;i++) { if(!updated[i]) { updated[i]=true; stage.stage[i] = e.type; --updatedcount; } } if(updatedcount==0) break; } } } class Stage{ long scoreA=0,scoreB=0; State[] stage; Stage(int size){ stage=new State[size]; Arrays.fill(stage, State.N); } void addBonus(int l,int r) { int a=0,b=0; for(int i=l;i<=r;i++) { switch (stage[i]) { case A: a++; break; case B: b++; break; case N: } } if(a>b) { scoreA += Math.max(a, b); }else if(a