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 <algorithm>
#include <queue>
#include <vector>
#include <map>
#include <string>

using namespace std;

void solve();

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

void solve() {
    while(1) {
        int n,m;
        cin >> n >> m;
        if(n == 0 && m == 0) break;
        int d[n],v[n];
        for(int i = 0; i < n; i++) {
            cin >> d[i] >> v[i];
        }
        int sum = 0;
        for(int i = 1; i <= m; i++) {
            int ma = 0;
            for(int j = 0; j < n; j++) {
                if(d[j] == i) ma = max(ma,v[j]);
            }
            sum += ma;
        }
        cout << sum << endl;
    }
}

C++: #include<cstdio>
#include<functional>
#include<algorithm>
using namespace std;
typedef pair<int,int> P;
int main(void)
{
	int n,m,i,j,d,v,vm[101],sum;
	while(1)	{
		scanf("%d %d",&n,&m);
		if(m==0 && n==0)	break;
		for(i=1;i<=m;i++)	vm[i]=0;
		for(i=0;i<n;i++)	{
			scanf("%d %d",&d,&v);
			vm[d]=max(vm[d],v);
		}
		sum=0;
		for(i=1;i<=m;i++)	sum+=vm[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<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_front(v);
        }
    }
    int sum;
    REP(i,n)
    {
        sum+=a.at(i).at(0);
    }
    cout<<sum<<endl;
}

C++: #include <iostream>

using namespace std;

int main(void){
	while(1){
		int n, m; cin >> n >> m;
		if(!n && !m) break;
		pair<int, int> p[101];
		for(int i=0; i<n; i++){
			cin >> p[i].first >> p[i].second;
		}
		int sum = 0;
		int top[101]={0};

		for(int i=0; i<n; i++){
			if(top[p[i].first] < p[i].second){
				sum += p[i].second;
				sum -= top[p[i].first];
				top[p[i].first] = p[i].second;
			}
		}
	
		cout << sum << endl;
	}
}

C++: #include<bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
int main(){
    int n,m;
    while(cin>>n>>m,n){
        int a[n+1]={},x,y,ans=0;
        r(i,n){
            cin>>x>>y;
            a[x]=max(a[x],y);
        }
        r(i,n+1)ans+=a[i];
        cout<<ans<<endl;
    }
}

C++: #include <iostream>
#define llint long long

using namespace std;

llint n, m;
llint a[105];

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

C++: //C
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdalign>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>


//Hang in there!

using namespace std;


int main() {
	int N, M;
	N = M = 1;
	while (N != 0 && M != 0) {
		cin >> N >> M;
		if (N == 0 && M == 0) {
			return 0;
		}
		vector<pair<int, int>>data(N);
		for (int i = 0; i < N; i++) {
			cin >> data[i].first >> data[i].second;
		}
		sort(data.begin(), data.end());
		int ans = 0;
		int dif = M;
		for (int i = N - 1; i >= 0; i--) {
			if (data[i].first == dif) {
				ans += data[i].second;
				dif--;
			}
		}
		cout << ans << endl;
	}
}

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

int main() {
    int n, m;
    while (cin >> n >> m, n) {
        vector<vector<int>> candy(m);
        while (n--) {
            int d, v; cin >> d >> v; d--;
            candy[d].emplace_back(v);
        }
        int sum = 0;
        for (int d = 0; d < m; d++) {
            sort(candy[d].rbegin(), candy[d].rend());
            sum += candy[d][0];
        }
        cout << sum << endl;
    }
    return 0;
}

C++: #include<bits/stdc++.h>
#include<stdio.h>
using namespace std;
int main()
{
   int  n,t;

    while(scanf("%d%d",&n,&t)!=EOF&&n!=0)
    {
        int sum=0;
        int f[200]={0};
        for(int i=0;i<n;i++)
        {
            int x,y;
            scanf("%d%d",&x,&y);
           f[x]=max(f[x],y);
        }
        for(int i=1;i<=t;i++)
            sum+=f[i];
        printf("%d\n",sum);
    }
    return 0;
}