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>
#define range(i,a,b) for(long long i = (a); i < (b); i++)
#define rep(i,b) for(long long i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;
using namespace std;
 
template <typename X, typename T>
auto vectors(X x, T a) {
	return vector<T>(x, a);
}
template <typename X, typename Y, typename Z, typename... Zs>
auto vectors(X x, Y y, Z z, Zs... zs) {
	auto cont = vectors(y, z, zs...);
	return vector<decltype(cont)>(x, cont);
}
template<typename T>
ostream& operator << (ostream& os, vector<T>& v){
	rep(i,v.size()){ os << v[i] << (i == v.size() - 1 ? "" : " "); } return os;
}
template<typename T>
istream& operator >> (istream& is, vector<T>& v){
	for(T& x: v){ is >> x; } return is;
}

int main(){
	int n, m;
	while(cin >> n >> m, n){
		map<int,int> a;
		rep(i,n){
			int d, v;
			cin >> d >> v;
			a[d] = max(a[d], v);
		}

		int sum = 0;
		rep(i,m){
			sum += a[i + 1];
		}
		cout << sum << endl;
	}
}

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

using namespace std;

int main() {
	int n, m; 
	while (cin >> n >> m && (n || m)) {
		vector<pair<int, int> > dv(n);
		int d, v;
		for (int i = 0; i < n; ++i) {
			cin >> d >> v;
			dv[i] = make_pair(d, v);
		}
		sort(dv.begin(), dv.end(), greater<pair<int, int> >());
		int ans = 0, level = m;
		for (int i = 0; i < n; ++i) {
			if (dv[i].first == m) {
				ans += dv[i].second;
				m--;
			}
		}
		cout << ans << endl;
	}

	return 0;
}

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

int main() {
    int N, M;
    while (cin >> N >> M, N || M) {
	vector<int> max_num(M);
	for (int i = 0; i < N; i++) {
	    int d, v;
	    cin >> d >> v;
	    max_num[d-1] = max(max_num[d-1], v);
	}

	int sum = 0;
	for (auto i : max_num) sum += i;
	cout << sum << endl;
    }

    return 0;
}

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

int main(){

    int n, m;
    while(true){
        cin>>n>>m;
        if(n==0)break;
        vector<int>vec(m+1, 0);
        for(int i=0;i<n;i++){
            int d, v;
            cin>>d>>v;
            vec[d] = max(vec[d], v);
        }
        int ans=0;
        for(int i=1;i<=m;i++){
            ans+=vec[i];
        }
        cout<<ans<<endl;
    }
    return 0;
}

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

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

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

using i64 = int64_t;

int v[102]={0};

void init(){
    for(int i=0;i<=100;++i)v[i]=0;
}

int main(){
    int n, m;
    while(cin >> n >> m, n != 0){
        init();
        for(int i=0;i<n;++i){
            int di, vi;
            cin >> di >> vi;
            v[di] = max(v[di], vi);
        }
        int sum = 0;
        for(int i=1;i<=m;++i)sum += v[i];
        cout << sum << endl;
    }

    return 0;
}

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

const int MAX_M=101;

int N,M,d,v,ans;
vector<int> vs(MAX_M);

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    while(cin >> N >> M,N){
        for (int i=0;i<M;++i) vs[i]=0;
        for (int i=0;i<N;++i){
            cin >> d >> v; --d;
            vs[d]=max(vs[d],v);
        }
        ans=0;
        for (int i=0;i<M;++i) ans+=vs[i];
        cout << ans << '\n';
    }
}

C++: #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define sz(x) ((int)(x).size())
#define sq(x) ((x)*(x))
#define fi first
#define sec second
#define SORT(x) sort((x).begin(),(x).end())
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define repn(i,a,n) for(int (i)=(a);(i)<(int)(n);(i)++)
#define EQ(a,b) (abs((a)-(b))<eps)
int solve(){
	int N,M;
	cin >> N >> M;
	if(N+M==0)return 1;
	vector<int> d(N),v(N);
	vector<int> mx(M);
	for(int i=0;i<N;i++){
		cin >> d[i] >> v[i];
		d[i]--;
		mx[d[i]]=max(mx[d[i]],v[i]);
	}
	int ans = 0;
	for(int i=0;i<M;i++)ans += mx[i];
	cout << ans << endl;
	return 0;
}
int main(){
	while(!solve()){}
	return 0;
}

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

int main(){
  int n, m;
  while(cin >> n >> m, n || m){
    map<int, int> mp;
    for(int i = 0; i < m; i++){
      mp[i + 1] = 0;
    }

    int d, v;
    for(int i = 0; i < n; i++){
      cin >> d >> v;
      mp[d] = max(mp[d], v);
    }

    int ans = 0;
    for(auto a : mp){
      ans += a.second;
    }
    cout << ans << endl;
  }
}

C++: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N,M;
    while(cin >> N >> M && N){
        vec<int> ma(M+1);
        for(int i=0;i<N;i++){
            int c,d;
            cin >> c >> d;
            ma[c] = max(ma[c],d);
        }
        cout << accumulate(ma.begin(),ma.end(),0) << "\n";
    }
}

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

#define vi vector<int>
#define rep(i, n) for (int i = 0; i < n; i++)

int main () {
  while (true) {
    int n, m;
    cin >> n >> m;
    if (n == 0 && m == 0) return 0;
    vi d(n), v(n);
    vi ma(m);
    rep (i, n) {
      cin >> d[i] >> v[i];
      d[i]--;
      ma[d[i]] = max(ma[d[i]], v[i]);
    }
    int sum = 0;
    rep (i, m) {
      sum += ma[i];
    }
    cout << sum << endl;
    
  }
}