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;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
inline ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
inline ll lcm(ll a, ll b) { return a / gcd(a, b)*b; }
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T>& V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> >& Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T>& mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }
template<typename T>vector<T> make_v(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>auto make_v(size_t a,Ts... ts){return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));}
template<typename T,typename V> typename enable_if<is_class<T>::value==0>::type fill_v(T &t,const V &v){t=v;}
template<typename T,typename V> typename enable_if<is_class<T>::value!=0>::type fill_v(T &t,const V &v){for(auto &e:t) fill_v(e,v);}
/*
 <url:http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2823&lang=jp>
 問題文============================================================
 =================================================================
 解説=============================================================
 ================================================================
 */

template<class Type>
Type solve(Type res = Type()){
    int N,M;
    while(cin >> N >> M,N){
        map<int,int> mp;
        for(int i = 0; i < N;i++){
            int d,v; cin >> d >> v;
            mp[d] = max(mp[d],v);
        }
        int ans = 0;
        for(auto p:mp){
            ans += p.second;
        }
        cout << ans << endl;
    }
    return res;
}
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    solve(0);
    //cout << fixed << setprecision(15) << solve<ll>() << endl;
    return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rep3(i, l, n) for (int i = l; i < n; ++i)
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define out(a) cout << a << endl
#define SZ(v) (int)v.size()
#define inf (int)(1e9+7)

int main() {
    int n, m;
    while (cin >> n && n) {
        cin >> m;
        vector<pii> v(n);
        rep(i, n) {
            cin >> v[i].F >> v[i].S;
            v[i].S *= -1;
        }
        sort(all(v));
        //rep(i, SZ(v)) cout << v[i].F << " " << v[i].S << endl;
        //rep3(i, 1, n) {  // 事故る
        rep3(i, 1, SZ(v)) {
            if (v[i].F == v[i - 1].F) {
                v.erase(v.begin() + i);
                i--;
            }
        }
        int sum = 0;
        rep(i, SZ(v)) {
            sum += v[i].S;
        }
        out(-sum);
    }
}

C++: #include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
    int n,m;
    while(cin >> n >> m, n){
        vector<int> x(m+1,0);
        for(int i = 0; i < n; i++){
            int d,v;
            cin >> d >> v;
            x[d] = max(x[d], v);
        }
        int ans = 0;
        for(int i = 1; i <= m ; i++) ans += x[i];
        cout << ans << endl;
    }
}

C++: #include <bits/stdc++.h>

using namespace std;

#define FOR(i,a,b) for(int i(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second

template<typename A, typename B> inline bool chmax(A &a, B &b) { if (a<b) {a = b; return 1;} return 0;}
template<typename A, typename B> inline bool chmin(A &a, B &b) { if (a>b) {a = b; return 1;} return 0;}

typedef long long ll;
typedef pair<int, int> pii;

const ll INF = 1e9+100;
const bool debug = 0;

ll N, M;
ll d, v, ans;
ll S[112];

int main() {
	while (cin>>N>>M, (N||M)){
		fill(S, S+112, 0);
		ans = 0;
		REP( i, N ){
			cin>>d>>v;
			S[d] = max( S[d], v );
		}
		FOR( i, 1, M+1 ) ans += S[i];
		cout<<ans<<endl;
	}
	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define pb emplace_back
typedef long long ll;
typedef pair<int,int> pint;

int v[101];
int main(){
    int n,m,di,vi;
    while(cin>>n>>m,n|m){
        memset(v,0,sizeof(v));
        rep(i,n){
            cin>>di>>vi;
            --di;
            v[di]=max(v[di],vi);
        }
        int sum=0;
        rep(i,m) sum+=v[i];
        cout<<sum<<endl;
    }
    return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
main(){
  int n, m, d, v, sum;
  
  while(cin>>n>>m, n){

    int ma[100]={};
  
    for(int i=0;i<n;i++){
      cin>>d>>v;
      ma[d-1]=max(ma[d-1], v);
    }
    
    sum=0;
    for(int i=0;i<m;i++) sum+=ma[i];

    cout<<sum<<endl;
  }
  
  return 0;
}