import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Scanner;

public class prog {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String line = scanner.nextLine();
        String[] data = line.split(" ");
        Integer n = Integer.valueOf(Integer.parseInt(data[0]));
        Integer m = Integer.valueOf(Integer.parseInt(data[1]));

        List<Box> boxes = new ArrayList<Box>();
        int bCount = 0;
        int wCount = 0;
        for (int i = 0; i < n; i++) {
            String[] boxData = scanner.nextLine().split(" ");
            int whites = Integer.parseInt(boxData[0]);
            int blacks = Integer.parseInt(boxData[1]);
            bCount += blacks;
            wCount += whites;
            boxes.add(new Box(whites, blacks));
        }
        Collections.sort(boxes, new Comparator<Box>() {
            @Override
            public int compare(Box o1, Box o2) {
                return Integer.valueOf(o2.blacks - o2.whites).compareTo(o1.blacks - o1.whites);
            }
        });
        int resBCount = 0;
        int resWCount = 0;
        for (int i = 0; i < n / 2; i++) {
            Box box = boxes.get(i);
            resBCount += box.blacks;
            resWCount += box.whites;
        }
        resWCount = wCount - resWCount;

        System.out.println(resBCount + " " + resWCount);
        scanner.close();
    }

    public static class Box {
        public int whites;
        public int blacks;

        public Box(int whites, int blacks) {
            super();
            this.whites = whites;
            this.blacks = blacks;
        }
    }
}