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 <stdio.h>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
typedef long long int ll;
#define BIG_NUM 2000000000
#define MOD 1000000007
using namespace std;

int main(){

	int N,M,table[101],ans,d,v;

	while(true){
		scanf("%d %d",&N,&M);
		if(N == 0 && M == 0)break;

		for(int i = 1; i <= M; i++)table[i] = 0;

		ans = 0;

		for(int i = 0; i < N; i++){
			scanf("%d %d",&d,&v);
			table[d] = max(table[d],v);
		}

		for(int i = 1; i <= M; i++)ans += table[i];

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

   return 0;
}

C++: /////16:25~
/////A:

#include<iostream>

using namespace std;

int n,m;
int d[111],v[111];
int t[111];
int main(){

    while(true){
    cin>>n>>m;
    if(n==0&&m==0)break;
    for(int i=0;i<n;i++)cin>>d[i]>>v[i];
    for(int i=0;i<n;i++)t[d[i]]=max(t[d[i]],v[i]);
    int ans=0;

    for(int i=1;i<=m;i++)ans+=t[i];

    cout<<ans<<endl;


    for(int i=0;i<=m;i++)t[i]=0;
    }

    return 0;
}

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

int p[101];

void solve(int n, int m) {
    for (int i = 1; i <= m; i++) {
        p[i] = 0;
    }
    int d, v;
    for (int i = 0; i < n; i++) {
        cin >> d >> v;
        p[d] = max(p[d], v);
    }
    int ans = 0;
    for (int i = 1; i <= m; i++) {
        ans += p[i];
    }
    cout << ans << endl;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, M;
    while (true) {
        cin >> N >> M;
        if (N == 0 && M == 0) break;
        solve(N, M);
    }
    return 0;
}

C++: #include <bits/stdc++.h>
#define ll long long
#define INF INT_MAX 
#define mod 1000000007
using namespace std;
int main(){
    ll N,M;
    ll aho[1000];
    ll k=0;
    while(1){
    cin >> N >> M;
    if(N==0&&M==0) break;
    pair<int,int> P[N];
    for(int i=0;i<N;i++){
        cin >> P[i].first >> P[i].second;
    }
    sort(P,P+N);
    int ans = 0;
    int cnt = 0;
    int j=1;
    for(int i=0;i<N;i++){
        if(j==P[i].first){
            cnt = max(cnt,P[i].second);
            if(P[i+1].first!=j){
                j++;
                ans += cnt;
                cnt = 0;
            }
        }
    }
    aho[k] = ans;
    k++;
    }
    for(int i=0;i<k;i++){
        cout << aho[i] << endl;
    }
}

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

using ll = long long;

int main() {
    int N, M;
    while(cin >> N >> M, N) {
        vector<int> res(M+1);
        for(int i = 0 ; i < N; ++i) {
            int d, v;
            cin >> d >> v;
            res[d] = max(res[d], v);
        }
        cout << accumulate(res.begin(), res.end(), 0) << endl;
    }
}

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

int solve(int N, int M) {
    vector<vector<int>> problems(M);
    int d, v;
    for (int i = 0; i < N; i++) {
        cin >> d >> v;
        problems[d - 1].push_back(v);
    }
    int ret = 0;
    for (int i = 0; i < M; i++) {
        sort(problems[i].begin(), problems[i].end());
        ret += problems[i][problems[i].size() - 1];
    }
    return ret;
}

int main(void) {
    int N, M;
    vector<int> ans;
    while (1) {
        cin >> N >> M;
        if (!N && !M) break;
        ans.push_back(solve(N, M));
    }
    for (int a : ans) cout << a << endl;
}

C++: #include <bits/stdc++.h>
using namespace std;
#define SZ(x) (int)(x.size())
#define REP(i, n) for(int i=0;i<(n);++i)
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define RREP(i, n) for(int i=(int)(n)-1;i>=0;--i)
#define RFOR(i, a, b) for(int i=(int)(b)-1;i>=(a);--i)
#define ALL(a) a.begin(),a.end()
#define DUMP(x) cerr<<#x<<" = "<<(x)<<endl
#define DEBUG(x) cerr<<#x<<" = "<<(x)<<" (L"<<__LINE__<<")"<< endl;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using P = pair<int, int>;
const double eps = 1e-8;
const ll MOD = 1000000007;
const int INF = INT_MAX / 2;
const ll LINF = LLONG_MAX / 2;
template <typename T1, typename T2>
bool chmax(T1 &a, const T2 &b) {
    if (a < b) { a = b; return true; }
    return false;
}
template <typename T1, typename T2>
bool chmin(T1 &a, const T2 &b) {
    if (a > b) { a = b; return true; }
    return false;
}
template<typename T>
ostream &operator<<(ostream &os, const vector<T> &v) {
    os << "[";
    REP(i, SZ(v)) {
        if (i) os << ", ";
        os << v[i];
    }
    return os << "]";
}
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const map<T1, T2> &mp) {
    os << "{";
    int a = 0;
    for (auto &tp : mp) {
        if (a) os << ", "; a = 1;
        os << tp;
    }
    return os << "}";
}
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) {
    os << p.first << ":" << p.second;
    return os;
}


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    for (;;) {
        int n, m; cin >> n >> m;
        if (n == 0) break;
        vi ma(m);
        REP(i, n) {
            int d, v; cin >> d >> v;
            chmax(ma[d-1], v);
        }
        cout << accumulate(ALL(ma), 0) << endl;
    }

    return 0;
}

C++: #include<iostream>
#include<algorithm>

using namespace std;
int n,m,d[200],v[200];
int maxi[200];
int main() {
    while(1) {
        cin >> n >> m;
        if(n == 0)break;
        for(int i =0;i < n;i++)cin >> d[i] >> v[i];

        for(int i = 1;i <= m;i++)maxi[i] = 0;
        for(int i = 0;i < n;i++)maxi[d[i]] = max(maxi[d[i]],v[i]);

        int sum = 0;
        for(int i = 1;i <= m;i++)sum += maxi[i];
        cout << sum << endl;
    }
    return 0;
}