Go: package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

func main() {
	io := NewIo()
	defer io.Flush()
	for {
		n, m := io.NextInt(), io.NextInt()
		if n == 0 {
			break
		}
		p := make([][]int, m)
		for i := 0; i < n; i++ {
			d, v := io.NextInt()-1, io.NextInt()
			p[d] = append(p[d], v)
		}
		sum := 0
		for i := 0; i < m; i++ {
			max := 0
			for _, v := range p[i] {
				max = intMax(v, max)
			}
			sum += max
		}
		io.Println(sum)
	}
}

func intMax(a, b int) int {
	if a < b {
		return b
	}
	return a
}

// I/O template
type Io struct {
	reader    *bufio.Reader
	writer    *bufio.Writer
	tokens    []string
	nextToken int
}

func NewIo() *Io {
	return &Io{
		reader: bufio.NewReader(os.Stdin),
		writer: bufio.NewWriter(os.Stdout),
	}
}

func (io *Io) Flush() {
	err := io.writer.Flush()
	if err != nil {
		panic(err)
	}
}

func (io *Io) NextLine() string {
	var buff []byte
	for {
		line, isPrefix, err := io.reader.ReadLine()
		if err != nil {
			panic(err)
		}
		buff = append(buff, line...)
		if !isPrefix {
			break
		}
	}
	return string(buff)
}

func (io *Io) Next() string {
	for io.nextToken >= len(io.tokens) {
		line := io.NextLine()
		io.tokens = strings.Fields(line)
		io.nextToken = 0
	}
	s := io.tokens[io.nextToken]
	io.nextToken++
	return s
}

func (io *Io) NextInt() int {
	i, err := strconv.Atoi(io.Next())
	if err != nil {
		panic(err)
	}
	return i
}

func (io *Io) NextFloat() float64 {
	i, err := strconv.ParseFloat(io.Next(), 64)
	if err != nil {
		panic(err)
	}
	return i
}

func (io *Io) Println(a ...interface{}) {
	fmt.Fprintln(io.writer, a...)
}

func (io *Io) Printf(format string, a ...interface{}) {
	fmt.Fprintf(io.writer, format, a...)
}

func (io *Io) PrintIntSlice(a []int) {
	b := []interface{}{}
	for _, x := range a {
		b = append(b, x)
	}
	io.Println(b...)
}

func (io *Io) PrintStringSlice(a []string) {
	b := []interface{}{}
	for _, x := range a {
		b = append(b, x)
	}
	io.Println(b...)
}

func Log(name string, value interface{}) {
	fmt.Fprintf(os.Stderr, "%s=%+v\n", name, value)
}

func ExampleIo() {
	io := NewIo()
	defer io.Flush()
	a := make([]int, 0, 3)
	a[0], a[1], a[2] = io.NextInt(), io.NextInt(), io.NextInt()
	io.Println(a)
	io.PrintIntSlice(a)
	Log("io", a)
}

C++: #include <bits/stdc++.h>
using namespace std;

// region template
#define rep(i, a, b) for (int i = (a); i < (b); ++i)
#define trav(a, x) for (auto &a : x)
#define all(x) begin(x), end(x)
#define sz(x) (ll)(x).size()
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;

ll gcd(ll a, ll b) { return __gcd(a, b); }

ll euclid(ll a, ll b, ll &x, ll &y) {
    if (b) {
        ll d = euclid(b, a % b, y, x);
        return y -= a / b * x, d;
    }
    return x = 1, y = 0, a;
}

typedef unsigned long long ull;
typedef long double ld;
ull mod_mul(ull a, ull b, ull M) {
    ll ret = a * b - M * ull(ld(a) * ld(b) / ld(M));
    return ret + M * (ret < 0) - M * (ret >= (ll)M);
}
ull mod_pow(ull b, ull e, ull mod) {
    ull ans = 1;
    for (; e; b = mod_mul(b, b, mod), e /= 2)
        if (e & 1)
            ans = mod_mul(ans, b, mod);
    return ans;
}

const ll mod = 1000000007;
struct Mod {
    ll x;
    Mod(ll xx) : x(xx) {}
    Mod operator+(Mod b) { return Mod((x + b.x) % mod); }
    Mod operator-(Mod b) { return Mod((x - b.x) % mod); }
    Mod operator*(Mod b) { return Mod((x * b.x) % mod); }
    Mod operator/(Mod b) { return *this * invert(b); }
    Mod invert(Mod a) {
        ll x, y, g = euclid(a.x, mod, x, y);
        assert(g == 1);
        return Mod((x + mod) % mod);
    }
    Mod operator^(ll e) {
        if (!e)
            return Mod(1);
        Mod r = *this ^ (e / 2);
        r = r * r;
        return e & 1 ? *this * r : r;
    }
};
// endregion

int main() {
    cin.sync_with_stdio(0);
    cin.tie(0);
    cin.exceptions(cin.failbit);

    for (;;) {
        int n, m; cin >> n >> m;
        if (!n) break;
        vector<int> vv(m + 1);
        rep(i, 0, n) {
            int d, v; cin >> d >> v;
            vv[d] = max(vv[d], v);
        }
        int ans = 0;
        for (int i = 1; i <= m; i++) ans += vv[i];
        cout << ans << endl;
    }
}

C++: #include <bits/stdc++.h>
using namespace std;

int N, M;
vector<int> s;

bool enough(int X) {
    int L = 1;
    for (int i = 0; i < M; ++i) {
        int idx = distance(begin(s), lower_bound(begin(s), end(s), L + X));
        if (idx == N) return false;
        int diff;
        if (idx == 0) {
            diff = abs(L - s[idx]);
        } else {
            diff = min(abs(L - s[idx - 1]), abs(L - s[idx]));
        }
        L += max(1, X - diff);
    }
    return true;
}

int main() {
    while (cin >> N >> M, N) {
        s = vector<int>(N);
        for (int i = 0; i < N; ++i) cin >> s[i];
        int ng = -1, ok = s[N - 1];
        while (ok - ng > 1) {
            int m = (ng + ok) / 2;
            ( (enough(m)) ? ng : ok ) = m;
        }
        cout << (!(enough(ok)) ? -1 : ok) << endl;
    } 
    return 0;
}

C++: #include<bits/stdc++.h>
#define rep(i,a,b) for (int i = (a); i < (b); i++)
#define REP(i,n) rep(i,0,n)
using namespace std;

int main()
{
    int s[5];
  REP(z,5){
    
    int n,m;
    cin>>n>>m;
    vector<int>a(m);
    REP(i,n)
    {
        int d,v;
        cin>>d>>v;
        d--;
        if(v>a.at(d))
        {
            a.at(d)=v;
        }
    }
    int sum=0;
    REP(i,m)
    {
        sum+=a.at(i);
    }
    s[z]=sum;
  }
  REP(i,5){
    cout<<s[i]<<endl;
  }
}

C++: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int mod = 1e9 + 7;
const int inf = (1 << 30) - 1;
const ll infll = (1LL << 61) - 1;

int N, M;

int main()
{
    while (cin >> N >> M)
    {
        if (N == 0 && M == 0)
            return 0;
        map<int, int> mp;
        int ans = 0;
        for (int i = 0; i < N; i++)
        {
            int d, v;
            cin >> d >> v;
            mp[d] = max(mp[d], v);
        }
        for (auto &p : mp)
        {
            ans += p.second;
        }
        cout << ans << endl;
    }
}

C++: #include <iostream>
using namespace std;
int main(void){
  for(;;){
    int N, M;
    cin >> N >> M;
    if(N == 0 && M == 0){ return 0; }
    int d[N], v[N];
    for(int i = 0 ; i < N ; i++){
      cin >> d[i] >> v[i];
    }
    int max[N];
    for(int i = 0 ; i < N ; i++){
      max[i] = -1;
    }
    for(int i = 0 ; i < N ; i++){
      if(max[d[i]] < v[i]){max[d[i]] = v[i];}
    }
    int ans = 0;
    for(int i = 0 ; i < N ; i++){
      ans += max[i];
    }
    cout << ans << endl;
  }
}

C++: #define  _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"
#pragma comment (linker, "/STACK:526000000")

using namespace std;
typedef string::const_iterator State;
#define eps 1e-11L
#define MAX_MOD 1000000007LL
#define GYAKU 500000004LL

#define MOD 998244353LL
#define seg_size 262144*2LL
#define pb push_back
#define mp make_pair
typedef long long ll;
#define REP(a,b) for(long long (a) = 0;(a) < (b);++(a))
#define ALL(x) (x).begin(),(x).end()

unsigned long xor128() {
	static unsigned long x = 123456789, y = 362436069, z = 521288629, w = time(NULL);
	unsigned long t = (x ^ (x << 11));
	x = y; y = z; z = w;
	return (w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)));
}

void init() {
	iostream::sync_with_stdio(false);
	cout << fixed << setprecision(20);
}

#define int ll
void solve() {
	while (true) {
		int n, m;
		cin >> n >> m;
		if (n == 0) return;
		vector<int> inputs[200];
		REP(i, n) {
			int a, b;
			cin >> a >> b;
			inputs[a].push_back(b);
		}
		int ans = 0;
		for (int i = 1; i <= m; ++i) {
			sort(ALL(inputs[i]));
			ans += inputs[i].back();
		}
		cout << ans << endl;
	}
}
#undef int
int main() {
	init();
	solve();
}