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 <vector>
#include <utility>
#include <cstring>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#define INF (long)1e9
const int MOD = 1e9 + 7;
const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, 1, -1};
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n, m;
	while(cin >> n >> m, n | m)
	{
		vector<P> vec;
		bool flag[m + 1];
		memset(flag, false, sizeof(flag));
		int a, b;
		for(int i = 0; i < n; i++)
		{
			cin >> a >> b;
			vec.push_back(P(b, a));
		}
		sort(vec.begin(), vec.end());
		reverse(vec.begin(), vec.end());
		int ans = 0;
		for(int i = 0; i < n; i++)
		{
			if(flag[vec[i].second] == false)
			{
				flag[vec[i].second] = true;
				ans += vec[i].first;
			}
		}
		cout << ans << endl;
	}
	return 0;
}

C++: #include <cstdio>
#include <cstdint>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <numeric>

int testcase_ends() {
  size_t n, m;
  scanf("%zu %zu", &n, &m);
  if (n == 0 && m == 0) return 1;

  std::vector<int> d(m+1);
  for (size_t i = 0; i < n; ++i) {
    size_t di;
    int v;
    scanf("%zu %d", &di, &v);
    d[di] = std::max(d[di], v);
  }

  int res = std::accumulate(d.begin(), d.end(), 0);
  printf("%d\n", res);

  return 0;
}

int main() {
  while (!testcase_ends()) {}
}

C++: #include<bits/stdc++.h>
#define ll long long
#define fi first
#define se second
#define rep(i, j, k) for (auto i = j; i < k; i++)
#define rrep(i, j, k) for (auto i = j; i > k; i--)
using namespace std;

void solve(int &n, int &m) {
  int a[101];
  fill(a, a + 101, 0);
  rep(i, 0, n) {
    int d, v; cin >> d >> v; d--;
    a[d] = max(a[d], v);
  }
  int ans = 0;
  rep(i, 0, m) ans += a[i];
  cout << ans << endl;
}

int main() {
  int n, m;
  while (cin >> n >> m, n) solve(n, m);
}

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;
    vector<int>a(m);
    REP(i,n)
    {
        int d,v;
        cin>>d>>v;
        if(d==0){return 0;}
        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 <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <bitset>
#include <map>
#include <tuple>
#include <unordered_set>
#include <unordered_map>
#include <list>
#include <numeric>
#include <utility>
#include <iterator>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <ctime>
#include <cassert>
#include <random>
#include <cstring>

#define rep(i,n) for(int i=0;i<int(n);i++)
#define all(x) (x).begin(),x.end()
#define pb push_back

using namespace std;
using ll = long long;

const ll mod = 1000000007;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int ddx[8]={-1,-1,0,1,1,1,0,-1};
int ddy[8]={0,1,1,1,0,-1,-1,-1};
bool debug=false;

/*---------------------------------------------------*/

void solve(int& N, int& M){
  vector<int> vec(M + 1, 0);
  int d, v;
  for(int i = 0; i < N; i++) {
    cin >> d >> v;
    vec[d] = max(vec[d], v);
  }
  int ans = 0;
  for(int i = 0; i < vec.size(); i++) ans += vec[i];
  cout << ans << endl;
}

int main(){
  int N, M;
  while(cin >> N >> M) {
    if(N == 0 && M == 0) break;
    solve(N, M);
  }
  return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <climits>

#define LP(i,n) for(int i=0;i<n;i++)
#define Mset(x,v) memset(x,v,sizeof(x))
#define INF INT_MAX

using namespace std;
using LL=long long;

int V[105];

int main(){
    int N,M,d,v,sum;
    while(1){
        cin>>N>>M;
        Mset(V,0);
        sum=0;
        if(N==0&&M==0) break;
        LP(i,N){
            cin>>d>>v;
            V[d-1]=max(V[d-1],v);
        }
        LP(i,M){
            sum+=V[i];
        }
        cout<<sum<<endl;
    }
    return 0;
}

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

int main() {
    int n, m;
    while (cin >> n >> m, n + m) {
        vector<int> rec(m, -1e9);
        for (int i = 0; i < n; i++) {
            int d, v; cin >> d >> v;
            d--;
            rec[d] = max(rec[d], v);
        }
        int sum = 0;
        for (int i = 0; i < m; i++)
            sum += rec[i];
        cout << sum << endl;
    }
}

C++: #include "bits//stdc++.h"
using namespace std;
typedef long long ll;
#define ALL(v) (v).begin(),(v).end()
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;
int max_v[101];
int main() {
	int N, M;
	while (cin >> N >> M, N) {
		memset(max_v, 0, sizeof(max_v));
		for (int i = 0; i < N; i++) {
			int d, v;
			cin >> d >> v;
			max_v[d] = max(max_v[d], v);
		}
		int ans = 0;
		for (int i = 1; i <= M; i++) ans += max_v[i];
		cout << ans << endl;
	}
}