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"

#define REP(i, n ,N) for(ll i = (n); i < (N); i++)
#define p(s) cout<<(s)<<endl
#define p2(a, b) cout<<(a)<<" "<<(b)<<endl
using namespace std;
typedef long long ll;
ll MOD = 1e9+7;
ll inf = 1e18;

ll N, M;

int main(){
	while(cin >> N >> M && N > 0 && M > 0){
		priority_queue<ll> q[110];
		ll ans = 0;
		REP(i,0,N){
			ll d, v;
			cin >> d >> v;
			d--;
			q[d].push(v);
		}
		REP(i,0,M){
			ans += q[i].top();
		}
		p(ans);
	}

	return 0;
}

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

int main(){
    int n,m;
    while(cin >> n >> m, n|m){
        int recomend[m] = {};
        for(int i= 0; i < n; i++){
            int d,v; cin >> d >> v;

            recomend[d-1] = max(recomend[d-1], v);
        }

        int sum = 0;
        for(int i = 0; i < m; i++){
            sum += recomend[i];
        }

        cout << sum << "\n";
    }
}

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

#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))

typedef long long LL;

int main(){
  int n,m;
  while(cin>>n>>m,n){
    int d[101]={};
  for(int i=0;i<n;i++){
    int d1,v;cin>>d1>>v;
    d[d1]=max(d[d1],v);
  }
  int cnt=0;
  for(int i=1;i<=m;i++){
    cnt+=d[i];
  }
  cout<<cnt<<endl;
}
  return 0;
}

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

using namespace std;

int main(){

  while(1){
    int N,M;
    cin>>N;
    cin>>M;

    if(N == 0 && M == 0){
      break;
    }

    vector<pair<int,int>> Q;
    for(int i = 0;i < N;++i){
      int d,v;
      cin>>d;
      cin>>v;

      Q.push_back(make_pair(d,v));
    }

    sort(Q.begin(),Q.end());
    reverse(Q.begin(),Q.end());

    int fi = 0;
    int ans = 0;
    for(pair<int,int> e : Q){
      int e2;
      if(fi == 0){
        e2 = e.first;
        ans += e.second;
        fi = 1;
      }
      else{ 
        if(e2 != e.first){
          ans += e.second;
          e2 = e.first;
        }
      }
    }
    cout<<ans<<endl;
  }

  return 0;

}

C++: #include <bits/stdc++.h>
#define INF 1e18
#define int long long
#define Rep(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) Rep(i, 0, n)
#define all(a) (a).begin(), (a).end()
using namespace std;
typedef pair<int, int> P;
typedef pair<int, P> PP;
const int mod = 1000000007;
//const int mod = 998244353;

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);

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

C++: #include <cstdio>
#include <map>
#include <algorithm>
using namespace std;
int p[101];

int main(){
    int n, m, d, v, sum;
    for (; ;) {
        scanf("%d %d", &n, &m);
        if (n == 0 && m == 0) break;
        fill(p, p+m+1, 0);
        sum = 0;
        for (int i = 0; i < n; i++) {
            scanf("%d %d", &d, &v);
            p[d] = max(p[d], v);
        }
        for (int i = 1; i <= m; i++) sum+=p[i];
        printf("%d\n", sum);
    }
    return 0;
}

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

using namespace std;

#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for(int i=(int)(s-1); i>=(int)(e); i--)
#define pb push_back
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;

template<typename T> T chmax(T& a, const T& b) {return a = (a > b ? a : b);}
template<typename T> T chmin(T& a, const T& b) {return a = (a < b ? a : b);}

int main() {
	int n, m;
	while (cin >> n >> m) {
		if (n == 0 && m == 0) break;
		vector<int> v(m);
		rep(i, n) {
			int a, b;
			cin >> a >> b;
			chmax(v[a - 1], b);
		}
		cout << accumulate(all(v), 0) << endl;
	}
	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
int main(void){
    // Your code here!
    int N,M;
    while (cin >> N >> M, N) {
        vector<vector<int>> Q(M);
        for (int i=0;i<N;i++) {
            int d,v;
            cin >> d >> v;
            Q[d-1].push_back(v);
        }
        int ans = 0;
        for (int i=0;i<M;i++) {
            sort(Q[i].begin(),Q[i].end(),greater<int>());
            ans += Q[i][0];
        }
        cout << ans << endl;
    }
}

C++: #include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<deque>
#include<regex>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
typedef int long long ll;


int main() {
    int n,m;
    while(true){
        cin>>n>>m;
        if(n==0&&m==0)break;
        vector<int> v(m,0);
        rep(i,n){
            int a,b;
            cin>>a>>b;
            a--;
            if(v[a]<b)v[a]=b;
        }int ans=0;
        rep(i,m){
            ans+=v[i];
        }
        cout<<ans<<endl;
    }

    return 0;
}

C++: #include<iostream>
#include<string>
#include<algorithm>
using namespace std;

int main(){
	
	while(1){
		int n,m;
		cin>>n>>m;
		
		if(n==0&&m==0) break;
	
	
	    int vv[100];
	    for(int i=1;i<=m;i++){
			vv[i]=0;
	    }
		
		int d[100],v[100];
		for(int i=0;i<n;i++){
			cin>>d[i]>>v[i];
			
			if(vv[d[i]]<v[i]){
				vv[d[i]]=v[i];
			}	
		}
		
		int ans=0;
		for(int i=1;i<=m;i++) ans+=vv[i];
		
		
		cout<<ans<<endl;
	}
	

	return 0;
}