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 <algorithm>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <set>
#include <stdlib.h>
#include <string>
#include <utility>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define loop(i, x, n) for (int i = (x); i < (n); i++)
#define all(v) (v).begin(), (v).end()
#define int long long
using namespace std;
const int MOD = 1e9 + 7;
const int INF = 1e10;
template<typename T> void cmax(T &a, T b) { a = max(a, b); }
template<typename T> void cmin(T &a, T b) { a = min(a, b); }

signed main() {
  int n, m;
  while (cin >> n >> m) {
    if (n == 0 && m == 0) break;
    map<int, int> mp;
    rep(i, n) {
      int d, v;
      cin >> d >> v;
      if (mp[d] < v) mp[d] = v;
    }
    int ans = 0;
    for (auto x : mp) {
      ans += x.second;
    }
    cout << ans << endl;
  }
  return 0;
}

C++: #include <iostream>
#include <vector>
#include <list>
#include <algorithm>
#include <string>
#include <sstream>
#include <stack>
#include <iomanip>
#include <numeric>
#include <queue>
#include <climits>
#include <set>
#include <complex>
#include <cmath>
#include <cstring>
#include <map>
using namespace std;
using ll = long long;
#define MOD 1000000007
#define INF 1LL << 59
const int MAX = 510000;

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

    int N, M;

    while (cin >> N >> M)
    {
        if (N == 0 && M == 0)
            break;
        vector<vector<int>> v(M + 1);
        for (int i = 0; i < N; ++i)
        {
            int d, t;
            cin >> d >> t;
            v[d].push_back(t);
        }

        for (int i = 1; i <= M; ++i)
        {
            sort(v[i].begin(), v[i].end(), greater<int>());
        }
        int ans = 0;
        for (int i = 1; i <= M; ++i)
        {
            ans += v[i][0];
        }
        cout << ans << endl;
    }

    return 0;
}

C++: #include<stdio.h>
int main(){
	int N,M,d[100],v[100],sum,val[100];
	for(;;){
		for(int i = 0;i<100;i++){
			val[i] = 0;
		}
		scanf("%d %d",&N,&M);
		if(N == 0&&M == 0)	break;
		for(int i=0;i<N;i++){
			scanf("%d %d",&d[i],&v[i]);
			if(val[d[i]-1]<v[i])	val[d[i]-1]=v[i];
		}
		sum = 0;
		for(int i=0;i<M;i++){
			sum = sum + val[i];
		}
		printf("%d\n",sum);
	}
}

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

    int s[101];
int main(void){
    int n,m;
    int a,b;
    cin>>n>>m;
    for(int i=0;i<n;i++){
        cin>>a>>b;
        s[a]=s[a]<b?b:s[a];
    }
    for(int i=1;i<=m;i++) cout<<s[i]<<endl;
    return 0;
}

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

int main(void){
	int n,m;
	int a,b;
	while(cin>>n>>m,n||m){
		int s[101];
		for(int i=0;i<101;i++)s[i]=0;
		for(int i=0;i<n;i++){
			cin>>a>>b;
			s[a]=s[a]<b?b:s[a];
		}
		cout<<accumulate(s+1,s+m+1,0LL)<<endl;
	}
	return 0;
}

C++: #include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = (1e+9)+7;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
typedef pair<ld, ld> LDP;
int main(){
	int n, m;
	while (cin >> n >> m, n) {
		int a[101] = {};
		rep(i, n) {
			int d, w; cin >> d >> w;
			a[d] = max(a[d], w);
		}
		int out = 0;
		rep1(i, m) {
			out += a[i];
		}
		cout << out << endl;
	}
	return 0;
}

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

int main(){
	int n,m;
	while(cin >> n >> m)
	{
		if(n==0) break;
		vector<priority_queue<int> > q(m);
		
		for(int i=0;i<n;i++)
		{
			int d,v;
			cin >> d >> v;
			d--;
			q[d].push(v);
		}
		int ans = 0;
		for(int i=0;i<m;i++)
		{
			ans += q[i].top();
		}
		cout << ans << endl;
	}
}

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

using namespace std;

int main(){

  int n, m, d[100], v[100];

  while(cin>>n>>m, 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<v[j]) ma=v[j];
      }
      sum+=ma;
    }
    cout<<sum<<endl;
  }

  return 0;
}

C++: #include <iostream>

using namespace std;

int N, M;
int maxv[105];

int main(void)
{
	while(1){
		cin >> N >> M;
		if( N == 0 && M == 0 ) break;
		
		for(int i = 1; i <= M; i++) maxv[i] = 0;
		
		int d, v;
		for(int i = 0; i < N; i++){
			cin >> d >> v;
			maxv[d] = max(maxv[d], v);
		}
		int ans = 0;
		for(int i = 1; i <= M; i++) ans += maxv[i];
		cout << ans << 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_front(v);
        }
    }
    int sum;
    REP(i,n)
    {
        sum+=a.at(i).at(0);
    }
    cout<<sum<<endl;
}