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;
typedef long long ll;

int main(){
	ll n,m,j=0;
    ll ans[50];
	while(cin>>n>>m){
		if(n==0&&m==0)break;
		ll d[n],v[n];
		vector<pair<ll,ll>>dv(n);
		for(ll i=0;i<n;i++){
			cin>>d[i]>>v[i];
			dv[i] = make_pair(d[i],v[i]);
		}
		sort(dv.begin(),dv.end());
		//for(int i=0;i<n;i++)cout<<dv[i].first<<endl;
		ll res = 0;
		for(ll i=0;i<n-1;i++){
			if(dv[i].first!=dv[i+1].first){
				res += dv[i].second;
			}else if(dv[i].first==m){
				break;
			}
		}
		res += dv[n-1].second;
//		cout<<dv[n-1].second<<endl;
		ans[j]=res;
		j++;
		//cout<<res<<endl;
	}

	for(int i=0;i<50;i++){
		if(i==j)break;
		cout<<ans[i]<<endl;
	}
}

C++: #include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
template <typename T> using V = vector<T>;

bool solve() {
    ll N, M;
    cin >> N >> M;

    if(!(N + M)) return false;

    V<V<ll>> prob(M);
    for(ll i = 0; i < N; i++) {
        ll d, v;
        cin >> d >> v;
        prob[d - 1].push_back(v);
    }

    ll ans = 0;
    for(const auto &ele : prob) ans += *max_element(ele.begin(), ele.end());
    cout << ans << endl;
    return true;
}

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

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=0; i<=100; i++){
		if(m[i]!=0){
			ans+=m[i];
		}
	}
	cout << ans << endl;
	
}

C++: #include <iostream>

using namespace std;

int main()
{
  int N, M;
  int max_v[101];
  int sum;
  
  while (1) {
    cin >> N >> M;
    if (N == 0 && M == 0) break;

    for (int& v : max_v) v = 0;

    while (N--) {
      int d, v;
      cin >> d >> v;
      if (v > max_v[d]) max_v[d] = v;
    }

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

C++: #include<iostream>
#include<math.h>
#include<vector>
#include<algorithm>
#include<queue>
#include<set>
#include<map>
#define REP(i, n) for(long long i = 0; i < n; ++i)
#define ALL(a) a.begin(), a.end()
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;

int main() {
	while(1) {
	int n, m;
	cin>>n>>m;
		if(n==0&&m==0) break;
	vector<P> d(n);
	REP(i, n) cin>>d[i].first>>d[i].second;
	sort(ALL(d));
	ll res = 0;
	REP(i, n - 1) if(d[i + 1].first > d[i].first) res += d[i].second;
		res += d[n - 1].second;
	cout<<res<<endl;
	}
}

C++: #include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;

namespace FastFourierTransform
{
	using C = complex< double >;

	void DiscreteFourierTransform(vector< C > &F, bool rev)
	{
		const int N = (int)F.size();
		const double PI = (rev ? -1 : 1) * acos(-1);
		for (int i = 0, j = 1; j + 1 < N; j++) {
			int k=N>>1;
			for (; k > (i ^= k); k >>= 1);
			if (i > j) {
				swap(F[i], F[j]);
			}
		}
		C w, s, t;
		for (int i = 1; i < N; i <<= 1) {
			for (int k = 0; k < i; k++) {
				w = polar(1.0, PI / i * k);
				for (int j = 0; j < N; j += i * 2) {
					s = F[j + k];
					t = C(F[j + k + i].real() * w.real() - F[j + k + i].imag() * w.imag(),
						F[j + k + i].real() * w.imag() + F[j + k + i].imag() * w.real());
					F[j + k] = s + t, F[j + k + i] = s - t;
				}
			}
		}
		if (rev) for (int i = 0; i < N; i++) F[i] /= N;
	}

	vector< long long > Multiply(const vector<long long int > &A, const vector<long long int > &B)
	{
		int sz = 1;
		while (sz <= A.size() + B.size()) sz <<= 1;
		vector< C > F(sz), G(sz);
		for (int i = 0; i < A.size(); i++) F[i] = A[i];
		for (int i = 0; i < B.size(); i++) G[i] = B[i];
		DiscreteFourierTransform(F, false);
		DiscreteFourierTransform(G, false);
		for (int i = 0; i < sz; i++) F[i] *= G[i];
		DiscreteFourierTransform(F, true);
		vector< long long > X(A.size() + B.size() - 1);
		for (int i = 0; i < A.size() + B.size() - 1; i++) X[i] = F[i].real() + 0.5;
		return (X);
	}
};

long long int comb(long long int a, long long int k) {
	if(k==0)return 1;
	if(k==a)return 1;
	return comb(a-1,k-1)+comb(a-1,k);
}

long long int solve(int k,const vector<int>&v,vector< int>nums, const int now) {
	if (now == 10) {
		long long int ans=1;
		int sum=accumulate(nums.begin(),nums.end(),0);
		int rest=sum;
		for (int i = 0; i < 10; ++i) {
			if (nums[i]) {
				ans*=comb(rest,nums[i]);
				rest-=nums[i];
			}
		}
		if (nums[0]) {
			long long int nans=1;
			int rest=sum-1;
			for (int i = 0; i < 10; ++i) {
				if (nums[i]) {
					if(i==0)nans*=comb(rest,nums[i]-1);
					else nans*=comb(rest,nums[i]);

					if(i==0)rest-=nums[i]-1;
					else rest-=nums[i];
				}
			}
			ans-=nans;
		}
		return ans;
	}
	else {
		if (v[now]) {
			long long int ans=0;

			for (int x = 1; x <= v[now];++x) {
				nums[now]=x;
				ans += solve(k, v, nums, now + 1);
			}
			return ans;
		}
		else {
			nums[now]=0;
			return solve(k,v,nums,now+1);
		}
	}
}

int main()
{
	while (true) {
		int N,M;cin>>N>>M;
		if(!N)break;
		vector<int>v(M,-100000);
		for (int i = 0; i < N; ++i) {
			int a;cin>>a;
			int b;cin>>b;
			v[a-1]=max(v[a-1],b);
		}
		cout<<accumulate(v.begin(),v.end(),0)<<endl;
	}
	return 0;
}