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;
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,n1,n2) for(int i=n1;i<n2;i++)
#define bFOR(i,n1,n2) for(int i=n1;i>=n2;i--)
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

typedef long long int ll;
typedef pair<ll,ll> Pi;
const int INF=(ll)(1LL<<30)-1;
const double INFd=100000000000.0;
const ll INFl=(ll)9223372036854775807;
const int MAX=10000;
const ll MOD=(ll)1e9+7;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a, b)*b;}
int dx[4]={0,1,0,-1},dy[4]={-1,0,1,0};

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

int n,m;
int d[110],v[110];
vector<int> pro[110];

int main(){
	while(1){
		cin>>n>>m;
		if(n==0&&m==0)break;
		REP(i,110)pro[i].clear();
		REP(i,n){
			cin>>d[i]>>v[i];
			pro[d[i]].push_back(v[i]);
		}
		int ans=0;
		for(int i=1;i<=m;i++){
			sort(pro[i].begin(),pro[i].end(),greater<int>());
			ans+=*(pro[i].begin());
		}
		cout<<ans<<endl;
	}
	return 0;
}

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

int main(){
  int n,m;
  int d[100] = {};
  int v[100] = {};
  int count[100] = {0};
  int n_count = 0;

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

    for(int i = 0; i < n; i++){
    cin >> d[i] >> v[i];
    }

    for(int j = 1; j <= m; j++){
      int max = 0;
      for(int t = 0; t < n; t++){
        if(d[t] == j && v[t] > max) max = v[t];
      }
      count[n_count] += max;
    }
    n_count++;
  }

  for(int x = 0; x < n_count; x++){
    cout << count[x] << endl;
  }

  return 0;
}

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-1]=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 <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]-1] < v[i]){max[d[i]-1] = v[i];}
    }
    int ans = 0;
    for(int i = 0 ; i < N ; i++){
      ans += max[i];
    }
    cout << ans << endl;
  }
}

C++: #include <bits/stdc++.h>
#define loop for(;;)
#define rep(i, n) for(long i = 0; i < (long)(n); ++i)
typedef std::vector<long> LI;

struct Solver {
   void solve() {
      long n, m; std::cin >> n >> m;
      if( n == 0 and m == 0 ) exit(0);
      LI ds(n), vs(n);
      rep(i, n) std::cin >> ds[i] >> vs[i];
      LI xs(m+1, 0);
      rep(i, n) {
         xs[ds[i]] = std::max(xs[ds[i]], vs[i]);
      }
      long res = 0;
      rep(i, m+1) {
         res += xs[i];
      }
      printf("%ld\n", res);
   }
};

int main() { loop std::shared_ptr<Solver>(new Solver())->solve(); }

C++: #pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
using ull=unsigned long long int;
using P=pair<ll,ll>;
template<class T> using V=vector<T>; 
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
const ll mod=1000000007;
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
ll lcm(ll c,ll d){return c/gcd(c,d)*d;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
int main(){
while(1){
int n,m;
cin>>n>>m;
if(n==0)return 0;
V<ll> ma(m,0);
for(int i=0;i<n;i++){
  ll d,v;
  cin>>d>>v;
  chmax(ma[d-1],v);
}
ll sum=0;
for(int i=0;i<m;i++)sum+=ma[i];
cout<<sum<<"\n";
}
}

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

using namespace std;

int main()
{
	int N,M,max=0;
	int d[100] = { 0 };
	int v[100] = { 0 };
	int anser=0;

	scanf("%d %d", &N, &M);

	for (int i = 0; i < N; i++) {
		scanf("%d %d", &d[i], &v[i]);
	}

	for (int i = 1; i <= M; i++) {
		for (int j = 0; j < N; j++) {
			if (d[j] == i) {
				if (v[j] > max) {
					max = v[j];
				}
			}
		}
		anser += max;
		max = 0;
	}
	
	cout << anser << endl;

	return 0;
}

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

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

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

int main()
{
	int N, M;
	while (cin >> N >> M, N | M) {
		vector<int> a(N);
		for (int i = 0; i < N; i++) {
			int d, v;
			cin >> d >> v; --d;
			a[d] = max(a[d], v);
		}
		cout << accumulate(a.begin(), a.end(), 0) << endl;
	}
	return 0;
}