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<bits/stdc++.h>
#include<vector>
 
using namespace std;


int main(){
	int N,M,ans=0; cin >> N >> M;
	int d[N+10],v[N+10],m[101]={};
	for(int i=0; i<N; i++){
		 cin >> d[i] >> v[i];
		 if(m[d[i]]<=v[i]){
			 m[d[i]]=v[i];
		 }
	}
	for(int i=1; i<=M; i++){
			ans+=m[i];
	}
	cout << ans << endl;
}

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

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

    while (1) {
        int N, M;
        cin >> N >> M;
        if (!N & !M) break;
        unordered_map<int, int> DV;
        for (int i = 1; i <= M; i++) {
            DV[i] = 0;
        }
        for (int i = 0; i < N; i++) {
            int d, v;
            cin >> d >> v;
            DV[d] = max(v, DV[d]);
        }
        int ans = 0;
        for (int i = 1; i <= M; i++) {
            ans += DV[i];
        }
        cout << ans << endl;
    }
}

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

#define dump(a) cerr << #a << " " << a << endl
#define rep(i,n) for(int i = 0; i < (n); i++)
using ll = long long;
using vi = vector<int>;

int main(){
  int n, m;
  while(cin >> n >> m, n){
    map<int, int> ans;
    rep(i,n){
      int d, v; cin >> d >> v;
      ans[d] = max(ans[d], v);
    }
    int num = 0;
    for(auto p : ans) num += p.second;
    cout << num << endl;
  }
}

C++: #include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <complex>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#define debug(x) cerr << #x << " = " << (x) << endl;


#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 100010

bool solve(){
  int n,m;
  int max_v[SIZE] ={};
  
  scanf("%d%d",&n,&m);

  if(n == 0) return false;
  
  for(int i=0;i<n;i++){
    int d,v;
    scanf("%d%d",&d,&v);

    max_v[d] = max(max_v[d], v);
  }

  int ans = 0;
  
  for(int i=1;i<=m;i++){
    ans += max_v[i];
  }

  printf("%d\n",ans);

  return true;
}

int main(){
  while(solve());
  
  return 0;
}

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

typedef long long ll;

int main(){
    
    for(ll N, M;cin>>N>>M,N;){
        vector<ll>vec(M + 1, 0);
         for(ll i = 0; i < N; i++){
            ll d, v;
            cin >> d >> v;
            vec[d] = max(vec[d], v);
        }
        ll ans = 0;
        for(ll i = 1; i <= M; i++)ans += vec[i];
        cout << ans << endl;
    }
    
    return 0;    
}

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

int main(){
  while(true){
    int N, M, temp[110] = {}, d, v ,sum = 0;
    cin>>N>>M;

    if(!N&&!M) break;

    for(int i = 1; i <= N; i++){
      cin>>d>>v;
      temp[d] = max(temp[d], v);
    }

    for(int i = 1; i <= M; i++){
      sum += temp[i];
    }
    cout<<sum<<endl;

  }
  return 0;
}

C++: #include <iostream>
#include <vector>
#include <queue>

using namespace std;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, m;
    vector<priority_queue<int>> problems;
    while(cin >> n >> m && n && m){
        problems.clear();
        problems.resize(m);
        for(int i = 0; i < n; i++){
            int d, v;
            cin >> d >> v;
            problems[d - 1].push(v);
        }
        int ans = 0;
        for(auto&& i : problems){
            ans += i.top();
        }
        cout << ans << "\n";
    }
}

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()
{
    vector<int>s(5);
  REP(j,5){
    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);
    }
    s.at(j)=sum;
  }
      REP(i,5)
    {
       cout<<s.at(i)<<endl;
    }
    
}

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

using namespace std;

#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define FOR(i, a, b) for(int i=(a);i<(b);i++)
#define REP(i, n) FOR(i, 0, n)
#define RFOR(i, a, b) for(int i=(a);i>=(b);i--)
#define RREP(i, n) RFOR(i, n, 0)
#define MFOR(i, m) for(auto i=(m).begin();i!=(m).end();i++)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((int)(x).size())

typedef long long int ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;

const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1 << 30;

template<typename T>
void printv(vector<T> const& s) {
  REP(i, SZ(s)) {
    cout << s[i] << " ";
  }
  cout << endl;
}

int main () {
  cin.tie(0);
  cout << setprecision(10);

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