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++: /*  -*- coding: utf-8 -*-
 *
 * 2823.cc: JAG Practice Contest
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 100;
const int MAX_M = 100;

/* typedef */

/* global variables */

int vs[MAX_M];

/* subroutines */

/* main */

int main() {
  for (;;) {
    int n, m;
    scanf("%d%d", &n, &m);
    if (n == 0) break;

    memset(vs, 0, sizeof(vs));

    for (int i = 0; i < n; i++) {
      int di, vi;
      scanf("%d%d", &di, &vi);
      di--;
      if (vs[di] < vi) vs[di] = vi;
    }

    int sum = 0;
    for (int i = 0; i < m; i++) sum += vs[i];
    printf("%d\n", sum);
  }
  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 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);
    }
    cout<<sum<<endl;
}

C++: #include<iostream>
#include<algorithm>
#include<numeric>
#include<vector>
#include<set>
#include<map>
#include <string>
#include <math.h>
#define cinf(n,x,y) for(int i=0;i<(n);i++) cin >> x[i] >>y[i];
typedef long long int ll;
using namespace std;

int main(){
  while(1){
    int n,m; cin >>n>>m;
    if(n==0&&m==0)break;
    vector<int> d(n),v(n);
    std::vector<vector<int> > V(m+1);
    V.clear();
    int ans=0;
    for(int i=0;i<n;i++){
      cin >> d[i] >> v[i];
      V[d[i]].push_back(v[i]);
    }
    for(int i=1;i<=m;i++){
      int cnt=0;
      for(auto p:V[i]){
        cnt=max(cnt,p);
      }
      ans+=cnt;
    }
    cout << ans << 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-1]<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 <bits/stdc++.h>
using namespace std;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ll long long
#define ld long double
#define all(a) (a).begin(),(a).end()
#define mk make_pair
ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;


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

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

int main(){
	int N,M,a,b;
	for(;~scanf("%d%d",&N,&M)&&N&&M;){
		vector<int>v(M);
		for(int i=0;i<N;i++){
			scanf("%d%d",&a,&b);
			v[a-1]=max(b,v[a-1]);
		}
		int s=0;
		for(int i=0;i<M;i++)s+=v[i];
		printf("%d\n",s);
	}
}

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

#define rep(i, n) for(int i = 0; i < n; i++)

typedef long long ll;
using namespace std;
int mod = 1000000007;

int main(void){
    int N, M;
    while(true){
        cin >> N >> M;
        if(N == 0) break;
        vector<priority_queue<int>> pq(M);
        rep(i, N){
            int d, v; cin >> d >> v;
            pq[d-1].push(v);
        }
        int acc = 0;
        rep(i, M) acc += pq[i].top();
        cout << acc << endl;
    }
    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[M];
    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 < M ; i++){
      ans += max[i];
    }
    cout << ans << endl;
  }
}

C++: #include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = uint32_t;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    int n, m;
    while(cin >> n >> m, n){
        vector<int> v(m);
        for (int i = 0; i < n; ++i) {
            int d, x;
            cin >> d >> x;
            v[d-1] = max(v[d-1], x);
        }
        cout << accumulate(v.begin(),v.end(), 0) << "\n";
    }
    return 0;
}

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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  while (true) {
    int n, m;
    cin >> n >> m;
    if (n + m == 0) return 0;
    
    vector<int> x(m);
    for (int i = 0; i < n; i++) {
      int d, v;
      cin >> d >> v;
      d--;
      x[d] = max(x[d], v);
    }
    
    int ans = 0;
    for (int i = 0; i < m; i++) ans += x[i];
    
    cout << ans << '\n';
  }
}