#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <numeric>
#include <functional>
#include <cctype>
#include <list>
#include <limits>
#include <cassert>
//#include <boost/multiprecision/cpp_int.hpp>

const double EPS = (1e-10);


using namespace std;
using Int = long long;
//using namespace boost::multiprecision;

const Int MOD = 1000000007;

long long mod_pow(long long x, long long n) {
    long long res = 1;
    for(int i = 0;i < 60; i++){
        if(n >> i & 1) res = res * x % MOD;
        x = x * x % MOD;
    }
    return res;
}

template<typename T>
T gcd(T a, T b) {
    return b != 0 ? gcd(b, a % b) : a;
}

template<typename T>
T lcm(T a, T b) {
    return a * b / gcd(a, b);
}

void fast_input() {
    cin.tie(0);
    ios::sync_with_stdio(false);
}


int solve(int N, int M) {
    vector<int> problems(M+1);
    int ret = 0;
    for (int i = 0; i < N; i++) {
        int d, v; cin >> d >> v;
        problems[d] = max(problems[d], v);
    }
    for (int i = 1; i <= M; i++) {
        ret += problems[i];
    }
    return ret;
}

int main(void) {
    int N, M;
    vector<int> ans;
    while (1) {
        cin >> N >> M;
        if (!N && !M) break;
        ans.push_back(solve(N, M));
    }
    for (int &i : ans) {
        cout << i << endl;
    }
    return 0;
}   

