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;
#define int long long
#define ll long long
#define fi first
#define se second
#define pb push_back
#define rep(i, s, n) for (int i = s; i < n; i++)
#define rrep(i, s, n) for (int i = (n)-1; i >= (s); i--)
#define REP(i,n) for(int i = 0;i < n; i++)
#define all(a) a.begin(),a.end()
typedef pair<int,int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
const long long MOD = 1000000007, INF = 1e18;

#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0)
 
template<class T>inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;}
template<class T>inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;}
template<typename T>vector<T>
make_v(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
	return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

template<typename T,typename V>
typename enable_if<is_class<T>::value==0>::type
fill_v(T &t,const V &v){t=v;}

template<typename T,typename V>
typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t,const V &v){
	for(auto &e:t) fill_v(e,v);
}



signed main(){
	IOS();
	vector<int>ans;
	while(1){
		int N,M;
		cin>>N>>M;
		if(!N&&!M)break;
		vector<int>v[M];
		rep(i,0,N){
			int D,V;
			cin>>D>>V;
			D--;
			v[D].push_back(V);
		}
		rep(i,0,M)sort(all(v[i]),greater<>());
		int sum = 0;
		rep(i,0,M)sum+=v[i][0];
		ans.push_back(sum);
	}
	for(auto e:ans){
		cout<<e<<endl;
	}
}

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

#define dump(a) cerr << #a << " " << a << endl
#define rep(i,n) for(int i = 0; i < (n); i++)
using ll = long long;
using vi = vector<int>;

int main(){
  int n, m;
  while(cin >> n >> m, n){
    map<int, int> ans;
    rep(i,n){
      int d, v; cin >> d >> v;
      ans[d] = max(ans[d], v);
    }
    int num = 0;
    for(auto p : ans) num += p.second;
    cout << num << endl;
  }
}

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

int main(int argc, char *argv[])
{
  int N, M;

  while (cin >> N >> M, N) {
    int d, v;
    vector<int> Dv, Vv;
    for (int i = 0; i < N; i++) {
      cin >> d >> v;
      Dv.push_back(d);
      Vv.push_back(v);
    }
    int sum = 0;
    
    for (int i = 1; i < M+1; i++) {
      int best = 0;
      for (int j = 0; j < N; j++) {
	if (Dv[j]==i) {
	  if (best < Vv[j]) {
	    best = Vv[j];
	  }
	}
      }
      sum += best;
      //cout << sum << endl;
    }
    cout << sum << endl;
  }
  
  return 0;
}

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

int main(void){
	int n, m;
	while(cin >> n >> m, n+m){
		vector<int> p(m, 0);
		for (int i = 0; i < n; ++i)
		{
			int d, v;
			cin >> d >> v;
			d--;
			p[d] = max(p[d], v);
		}
		int sum = 0;
		for(int i = 0; i < m; ++i){
			sum += p[i];
		}
		cout << sum << endl;
	}
	return 0;
}

C++: #include <iostream>
using namespace std;
int main(void){
  for(;;){
    int N, M;
    cin >> N >> M;
    if(N == 0 && M == 0){ return 0; }
    int d[N], v[N];
    for(int i = 0 ; i < N ; i++){
      cin >> d[i] >> v[i];
    }
    int max[N];
    for(int i = 0 ; i < N ; i++){
      max[i] = -1;
    }
    for(int i = 0 ; i < N ; i++){
      if(max[d[i]-1] < v[i]){max[d[i]] = v[i];}
    }
    int ans = 0;
    for(int i = 0 ; i < N ; i++){
      ans += max[i];
    }
    cout << ans << endl;
  }
}

C++: #include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>
#include <stack>
#include <assert.h>


using namespace std;
using ll = long long;
using ull = unsigned long long;

const ll INF = 1e16;
const ll MOD = 1e9 + 7;

#define REP(i, n) for(ll i = 0; i < n; i++)







int main(){
    int n, m;
    cin >> n >> m;
    while(n || m){
        vector<vector<ll>> a(m);
        REP(i, n){
            ll d, v;
            cin >> d >> v;
            a[d - 1].push_back(v);
        }
        
        int ans = 0;
        REP(i, m){
            ans += *max_element(a[i].begin(), a[i].end());
        }
        
        cout << ans << endl;
        
        cin >> n >> m;
    }
}

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

int s[101];
int main(void){
	int n,m;
	int a,b;
	while(cin>>n>>m,n||m){
		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 <bits/stdc++.h>
using namespace std;
int main() {
  while (true) {
    int n, m;
    cin >> n >> m;
    if (n == 0)
      break;
    map<int, int> mp;
    for (int i = 0; i < n; i++) {
      int a, b;
      cin >> a >> b;
      mp[a] = max(mp[a], b);
    }
    long long ans = 0;
    for (auto &v : mp)
      ans += v.second;
    cout << ans << endl;
  }
  return 0;
}