#include <bits/stdc++.h>
using namespace std;
#define REP(i, s, n) for (int i = s; i < n; ++i)
#define rep(i, n) REP(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define IINF INT_MAX
#define LLINF LLONG_MAX
#define DEBUG true
// sort(a.begin(), a.end(), std::greater<int>());

/*
std::vector<std::string> split(const std::string &input, char delimiter)
{
    std::istringstream stream(input);

    std::string field;
    std::vector<std::string> result;
    while (std::getline(stream, field, delimiter))
    {
        result.push_back(field);
    }
    return result;
}
*/

int main()
{
    int n, m;

    while (cin >> n >> m)
    {
        int mp[101] = {0};
        if (n == 0 && m == 0)
            break;
        int a, b;
        rep(i, n)
        {
            cin >> a >> b;
            mp[a] = max(mp[a], b);
        }
        int ans = 0;
        rep(i, 101)
        {
            if (mp[i] != 0)
                ans += mp[i];
        }
        cout << ans << endl;
    }
    return 0;
}