#include<iostream>
#include<vector>
#include<algorithm>
class Box {
	public:
	int whiteMarbles;
	int blackMarbles;
	int value;
	Box(int wm, int bm){
		this->whiteMarbles = wm;
		this->blackMarbles = bm;
		this->value = this->whiteMarbles - this->blackMarbles;
	}
};

int main(){
	int n,m,tempWM,tempBM;
	std::cin >> n;
	std::cin >> m;
	std::vector<Box> vectorOfBoxes, wBoxes,bBoxes;
	for(int counter = 0; counter < n; counter ++){
		std::cin >> tempWM;
		std::cin >> tempBM;
		Box a(tempWM,tempBM);
		vectorOfBoxes.push_back(a);
	}
	std::sort(vectorOfBoxes.begin(), vectorOfBoxes.end(), [](const Box &x, const Box &y){ return (x.value < y.value);});
	tempWM = tempBM = 0;
	int counter;
	for(counter = 0; counter < n/2; counter ++){
		tempBM += vectorOfBoxes[counter].blackMarbles; 
	}
	for(counter; counter < n; counter ++){
		tempWM += vectorOfBoxes[counter].whiteMarbles;
	}
	std::cout<< tempWM << " " << tempBM;
}