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;
int main(void){
    int n,m,d,v;
    while (cin>>n>>m) {
        if (n==0&&m==0) {
            break;
        } else {
            std::map<int, int> map;
            for (int i=0;i<n;i++) {
                cin>>d>>v;
                if (map.find(d)==map.end()) {
                    map.insert(make_pair(d,v));
                } else {
                    if (map.at(d)<v) {
                        map.erase(d);
                        map.insert(make_pair(d,v));
                    }
                }
            }
            int sum=0;
            for (int j=1;j<=m;j++) {
                sum+=map.at(j);
            }
            cout<<sum<<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;
			--a;
			d[a]=max(d[a],b);
		}
		int ans=0;
		for (int i = 0; i < m; ++i) ans+=d[i];
		cout<<ans<<endl;
	}
	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
int main() {
	while(1) {
		int n, m;
		cin >> n >> m;
		if((n == 0)&&(m == 0)) {
			break;
		} else {
			vector<int> arr(m, 0);
			int total = 0;
			for(int i = 0; i < n; i++) {
				int d, v;
				cin >> d >> v;
				d--;
				if(arr[d] < v) {
					total -= arr[d];
					arr[d] = v;
					total += arr[d];
				}
			}
			cout << total << endl;

		}
	}
	return 0;
}

C++: #include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <stack>
#include <functional>
#include <queue>
#include <cmath>
#include <set>
#include <map>
#include <numeric>

#define rep(i,j,k) for(int i=(int)j;i<(int)k;i++)
#define Sort(x) sort((x).begin(),(x).end())
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define vi vector<int>
#define INF (int)1e9
#define INFL 1e18
#define MOD 1e9+7
#define pb push_back
#define MP make_pair
typedef long long int ll;
typedef std::pair<int,int> P;
int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};

using namespace std;
int main() {
    int n,m;
    while(cin>>n>>m){
        if(!n&&!m)return 0;
        vector<int> v(101,0);
        rep(i,0,n){
            int x,va; cin>>x>>va;
            v[x]=max(v[x],va);
        }
    cout<<accumulate(all(v),0)<<endl;
    }
    
    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<vector<int>>a(m,vector<int>());
    REP(i,n)
    {
        int d,v;
        cin>>d>>v;
        if(v>a.at(d-1).at(0))
        {
            a.at(d-1).push_back(v);
        }
    }
    int sum;
    REP(i,n)
    {
        sum+=a.at(i).at(sum+=a.at(i).size());
    }
    cout<<sum<<endl;
}

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[50] = { 0 };
	int count = 0;

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

start:

	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[count] += max;
		max = 0;
	}

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

	if (!(N == 0 && M == 0)) {
		count++;
		max = 0;
		for (int i = 0; i < 100; i++) {
			d[i] = 0;
			v[i] = 0;
		}
		goto start;
	}
	
	for (int i = 0; i <= count; i++){
		cout << anser[i] << endl;
	}

	return 0;
}

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

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

    int n, m;
    while (cin >> n >> m) {
        if (n == 0) break;
        vector<vector<int>> as(m + 1);
        for (int i = 0; i < n; i++) {
            int a, b;
            cin >> a >> b;
            as[a].push_back(b);
        }
        for (int i = 1; i <= m; i++) {
            sort(as[i].rbegin(), as[i].rend());
        }
        long long ans = 0;
        for (int i = 1; i <= m; i++) {
            ans += as[i][0];
        }
        cout << ans << '\n';
    }
}

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 t,d,l;
  
  scanf("%d%d%d",&t,&d,&l);

  if(t == 0) return false;

  int ans = 0;
  int sec = 0;
  
  for(int i=0;i<t;i++){
    int x;

    scanf("%d",&x);

    if(t-1 == i) continue;
    
    sec--;
    if(x >= l){
      sec = d;
    }

    if(sec > 0) ans++;
  }

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

  return true;
}

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