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;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using vs=vector<string>;
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define range(i,a,n) for(ll i=(a);i<(n);i++)
#define LINF ((ll)1ll<<60)
#define INF ((int)1<<30)
#define EPS (1e-9)
#define MOD (1000000007ll)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI 3.1415926535897932384

int dx[]={1,0,-1,0,1,-1,-1,1},dy[]={0,1,0,-1,1,1,-1,-1};
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1; for(auto s:t){os<<(a?"":" ")<<s;a=0;} return os;}
void OUT(bool b){cout<<(b?"YES":"NO")<<endl;}
void Out(bool b){cout<<(b?"Yes":"No")<<endl;}
void out(bool b){cout<<(b?"yes":"no")<<endl;}
template<class T>
void puta(T&&t){cout<<t<<endl;}
template<class H,class...T>
void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}

int popcnt(int x){return __builtin_popcount(x);}
int popcnt(ll x){return __builtin_popcountll(x);}
int bsr(int x){return 31 - __builtin_clz(x);}
int bsr(ll x){return 63 - __builtin_clzll(x);}
int bsf(int x){return __builtin_ctz(x);}
int bsf(ll x){return __builtin_ctzll(x);}

/*他のライブラリを入れる場所*/

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n,m;
	while(cin>>n>>m,n){
		vi a(m,0);
		rep(i,n){
			int d,v; cin>>d>>v;
			a[d-1]=max(a[d-1],v);
		}
		cout<<accumulate(all(a),0)<<endl;
	}
	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define pi M_PI
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1000000007,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<int,int> P;

void Main() {
  int n,m;
  while(cin >> n >> m && n) {
    map<int,int> ma;
    rep(i,n) {
      int x,y;
      cin >> x >> y;
      if(!ma.count(x)) ma[x]=y;
      else ma[x]=max(ma[x],y);
    }
    int ans=0;
    REP(i,1,m+1) ans+=ma[i];
    pr(ans);
  }
}

int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}

C++: #include<bits/stdc++.h>
using namespace std;
int main(){
  while(1){
    int N,M;
    int A[101]={};
    cin>>N>>M;
    if(N==0&&M==0)break;
    for(int i=0;i<N;i++){
      int d,v;
      cin>>d>>v;
      A[d]=max(A[d],v);
    }
    int ans=0;
    for(int i=1;i<=M;i++){
      ans+=A[i];
    }
    cout<<ans<<endl;
  }
  return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
int main(){
    int n,m;
    while(cin>>n>>m&&n&&m){
	int data[101]={},d,v,sum=0;
	for(int i=0;i<n;++i){
	    cin>>d>>v;
	    data[d]=max(data[d],v);
	}
	for(int i=1;i<=m;++i) sum+=data[i];
	cout<<sum<<endl;
    }
    return 0;
}

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);

    int n, m;
    while (cin >> n >> m) {
        if (n == 0) break;
        vector<vector<int>> as(m + 1);
        for (int i = 0; i < n; i++) {
            int a, b;
            cin >> a >> b;
            as[a].push_back(b);
        }
        for (int i = 1; i <= m; i++) {
            sort(as[i].rbegin(), as[i].rend());
        }
        long long ans = 0;
        for (int i = 1; i <= m; i++) {
            ans += as[i][0];
        }
        cout << ans << '\n';
    }
}

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

int main()
{
    int n, m, d, v, a[101];

    while( cin >> n >> m )
    {
        if( n + m == 0 )
            break;

        for( int i = 0; i < 101; i++ )
            a[i] = 0;

        for( int i = 0; i < n; i++ )
        {
            cin >> d >> v;
            if( a[d] < v )
                a[d] = v;
        }
        
        int sum = 0;
        for( int i = 1; i <= m; i++ )
            sum += a[i];

        cout << sum << endl;
    }
    return 0;
}

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

int main(){
  while(1){
    int N,M;
    int t[101]={};
    cin>>N>>M;

    if(N==0)
      break;

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

    int ans=0;
    for(int i=1;i<=M;i++){
      ans+=t[i];
    }
    cout<<ans<<endl;
  }
  return 0;
}