#include <iostream>

using namespace std;

struct bile
{
    int w;
    int b;
    int dif;
};

int main()
{
    int n, m, i, firstBlack = 0, secondWhite = 0;
    bile b[100000];
    int first = 0, second = 0;
    
    cin >> n >> m;
    
    for(i = 0; i < n; i++)
    {
        cin >> b[i].w >> b[i].b;
        b[i].dif = b[i].w - b[i].b;
    }
    
    for(i = 0; i < n; i++)
    {
        if(b[i].dif > 0)
        {
            secondWhite += b[i].w;
            second++;
        }
        else if(b[i].dif < 0)
        {
            firstBlack += b[i].b;
            first++;
        }
    }
    
    if(first <= n/2 && second <= n/2)
    {
        for(i = 0; i < n && (n/2 - first); i++)
        {
            if(b[i].dif == 0)
            {
                firstBlack += b[i].b;
                first++;
            }
        }
        
        for(; i < n && (n/2 - second); i++)
        {
            if(b[i].dif == 0)
            {
                secondWhite += b[i].w;
                second++;
            }
        }
        
    }
    
    
    cout << firstBlack << " " << secondWhite;

   return 0;
}