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 <iostream>
#include <string>
#include <algorithm>
#include <utility>
#include <iomanip>
#include <functional>
#include <queue>
#include <stack>
#include <map>
#include <vector>
#include <cmath>
#include <cctype>
#include <cstdio>
#define ll long long
#define INF 1000000000000000001
#define MOD 1000000007
using namespace std;

using namespace std;

int main(){
    while(1){
        int N,M;
        cin >> N >> M;
        if(N==0 && M==0){
            break;
        }
        int vmax[1000]={};
        for(int i=0; i<N; i++){
            int d,v;
            cin >> d >> v;
            vmax[d]=max(vmax[d],v);
        }
        
        int sum=0;
        for(int i=1; i<=M; i++){
            sum+=vmax[i];
        }
        cout<<sum<<endl;
    }
}

C++: #include<stdio.h>
typedef struct{
	int d,v;
}num_t;
int main(){
	int N,M;
	while(1){
		scanf("%d %d",&N,&M);
		if(N==0&&M==0)break;
		num_t a[N];
		int max[100]={};
	for(int i=0;i<N;i++){
		scanf("%d %d",&a[i].d,&a[i].v);
	}
	for(int i=0;i<N;i++){
		for(int j=1;j<=M;j++){
			if(a[i].d==j){
				if(max[j]<a[i].v){
				max[j]=a[i].v;
				}
			}
		}
	}
	int x=0;
	for(int i=0;i<M;i++){
		x=x+max[i];
	}
		printf("%d\n",x);
	}
	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()
{
  while(1){
    
    int n,m;
    cin>>n>>m;
    if(n==0){return 0;}
    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);
    }
    cout<<sum<<endl;
  }
}

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

using namespace std;

int main() {
  int n, m;
  while (cin >> n >> m, n) {
    vector<vector<int>> D(110, vector<int>());
    for (int i = 0; i < n; i++) {
      int d, v;
      cin >> d >> v;
      D[d].emplace_back(v);
    }
    for (int i = 1; i <= m; i++) {
      sort(D[i].rbegin(), D[i].rend());
    }
    int ans = 0;
    for (int i = 1; i <= m; i++) {
      ans += D[i][0];
    }
    cout << ans << endl;
  }

  return 0;
}

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

using namespace std;
using ll = long long int;
using lc = complex<double>;

int main(void) {
    constexpr ll MOD = 1e9 + 7;
    constexpr double PI = acos(-1);
    cout << fixed << setprecision(32);
    cin.tie(0); ios::sync_with_stdio(false);

    while(1) {
        ll n, m;
        cin >> n >> m;
        if(!n) break;
        vector<ll> v(m);
        while(n--) {
            ll d, w;
            cin >> d >> w;
            d--;
            v[d] = max(v[d], w);
        }
        cout << accumulate(v.begin(), v.end(), 0ll) << endl;
    }
}

C++: #include<iostream>
using namespace std;
int main() {
	int n, m;
	while (cin >> n >> m, n) {
		int a[100] = {};
		for (int i = 0; i < n; i++) {
			int b, c; cin >> b >> c;
			if (a[b] < c)a[b] = c;
		}
		int ans = 0;
		for (int i = 1; i <= m; i++)ans += a[i];
		cout << ans << endl;
	}
}

C++: #include<bits/stdc++.h>
using namespace std;
int main(int argc, char const *argv[])
{
	int n,m;
	while(cin>>n>>m,n+m)
	{
		int d[105]={};
		int a,b;
		for (int i = 0; i < n; ++i)
		{
			cin>>a>>b;
			d[a]=max(d[a],b);
		}
		int ans=0;
		for (int i = 0; i < n; ++i) ans+=d[i];
		cout<<ans<<endl;
	}
	return 0;
}

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

int solve_testcase() {
    int N, M; cin >> N >> M;
    if(N == 0 and M == 0) return 1;

    vector<int> D(N), V(N);
    vector<int> ma(M + 1);
    for(int i=0; i<N; i++) {
        cin >> D[i] >> V[i];
        ma[ D[i] ] = max(ma[ D[i] ], V[i]);
    }

    cout << accumulate(ma.begin(), ma.end(), 0) << endl;
    return 0;
}

int main() {
    while(!solve_testcase());
    return 0;
}

C++: //#include <bits/stdc++.h>
//#include <stdio.h>
#include<iostream>
#include<cstdio>
#include<bitset>
#include<algorithm>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<string>
#include<string.h>
#include<cmath>
#include<utility>
#include<functional>
#include<map>
#include<set>
#include<cctype>
#include<fstream>
 
 
#define FOR(i, a, b) for( int i=(a);i<=(b);i++)
#define RFOR(i, a, b) for( int i=(a);i>=(b);i--)
#define LFOR(i, a, b) for( long long int i=(a);i<=(b);i++)
#define LRFOR(i, a, b) for(long long int i=(a);i>=(b);i--)
#define MOD 1000000007
#define INF 1000000000 //2000000000
#define LINF 1000000000000000000 //9000000000000000000
#define PI 3.14159265358979
#define MAXI 7500000
 
using namespace std;
typedef long long int ll;
typedef pair< long long int, long long  int> P;
 
int dy[5] = { 0,0,1,-1,0 };
int dx[5] = { 1,-1,0,0,0 };
 
int main(void){

	while(1){
		int n,m;
		int d[101],v[101];
		int total=0;
		int maxi=-1;

		cin>>n>>m;
		if(n==0&&m==0){
			break;
		}

		FOR(i,1,n){
			cin>>d[i]>>v[i];
		}

		FOR(i,1,m){
			maxi=-1;
			FOR(j,1,n){
				if(d[j]==i){
					if(v[j]>maxi){
						maxi=v[j];
					}
				}
			}
			total+=maxi;
		}

		cout<<total<<endl;

	}

}

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

#define int long long

signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

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

    vector<int> dif(M, 0);
    for ( int i = 0; i < N; i++ ) {
      int d, v;
      cin >> d >> v;
      d--;
      dif[d] = max(dif[d], v);    
    }

    int ans = 0;
    for ( int i = 0; i < M; i++ ) {
      ans += dif[i];    
    }

    cout << ans << endl;
  }
  
  return 0;
}