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 ull = unsigned long long;

const long double PI = acos(-1);
constexpr long double EPS = 1e-15;
constexpr int inf = 2e9;
constexpr ll INF = 2e18;
constexpr ll MOD = 1e9+7;
constexpr ll MOD1 = 998244353;
typedef pair<ll,ll> P;

//#define all(v) (v).begin(), (v).end()
#define rep(i,a,b) for (int i = (a); i < (b); i++)
#define REP(i,n) rep(i,0,n)
#define sz(s) (s).size()
#define pb push_back
#define fi first
#define se second
//#define mp make_pair

template<class T>
void maxi(T &a, const T &b){
  if(a < b) a = b;
}

int n,m;
int va[112];

void solve() {
  int vs = 0;
  for(int i = 1; i <= m; ++i){
    vs += va[i];
  }
  cout << vs << endl;
}

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

  /*Regular*/
  // if (argc > 1 && stoi(argv[1])) cin >> case_num;
  // REP(case_no, case_num) {
  //   cerr << endl << "case " << case_no + 1 << endl;
  //   solve();
  // }

  /*ICPC*/
  while (cin >> n >> m, n && m) {
    REP(i, n){
      int d, v;
      cin >> d >> v;
      maxi(va[d], v);
    }
    solve();
    REP(i, m) va[i] = 0;
  }

  return 0;
}

C++: 
#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
#include <complex>
using namespace std;
int main(){
    int i,j,k,l;
    int a,b,c,d;
    int dif,rec;
    int num,max;
    vector<int> res(100,0);
    a = 0;
    while(1){
        cin >> num >> max;
        if(num==0&&max==0){
            break;
        }
        vector<int> res1(max,0);
        for(i=0;i<num;i++){
            cin >> dif >> rec;
            if(res1[dif-1]<rec){
                res1[dif-1] = rec;
            }
        }
        for(i=0;i<max;i++){
            res[a] += res1[i];
        }
        a++;
    }
    for(i=0;i<a;i++){
        cout << res[i] << endl;
    }
    
}

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

typedef long long ll;

ll n,m;
ll ans;
ll a,b;
pair<ll,ll> x[500005];
bool used[500005];

bool solve(){
	cin >> n >> m;
	ans = 0;
	if(n == 0)return false;
	for(int i=0;i<n;i++){
		cin >> a >> b;
		x[i].first = a;
		x[i].second = b;
	}
	for(int i=1;i<=m;i++){
		used[i] = false;
	}
	sort(x,x+n);
	reverse(x,x+n);
	for(int i=0;i<n;i++){
		ll dif = x[i].first;
		ll v = x[i].second;
		if(used[dif]){
			continue;
		}else{
			ans += v;
			used[dif] = true;
		}
	}
	cout << ans << endl;
	return true;

}

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

C++: #include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"

using namespace std;

const long long int MOD = 1000000007;
//const int MOD = 1000000007;
//const int MOD = 998244353;

long long int N, M, K, H, W, L, R;
//int N, M, K, H, W, L, R;

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

	cin >> N >> M;
	while (N) {
		vector<int>v(M + 1);
		for (int i = 0; i < N; i++) {
			cin >> L >> R;
			v[L] = max(v[L], (int)R);
		}
		cout << accumulate(v.begin(), v.end(),0) << endl;
		cin >> N >> M;
	}
	return 0;
}

C++: #include "bits/stdc++.h"

#define REP(i,n) for(ll i=0;i<ll(n);++i)
#define RREP(i,n) for(ll i=ll(n)-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<ll(n);++i)
#define RFOR(i,m,n) for(ll i=ll(n)-1;i>=ll(m);--i)
#define ALL(v) (v).begin(),(v).end()
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

const int dx[8] = { 1,1,0,-1,-1,-1,0,1 };
const int dy[8] = { 0,1,1,1,0,-1,-1,-1 };


using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;



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

}

C++: #include <bits/stdc++.h>
using ll = long long;
#define int ll
#define rep(i, n) for (int i = 0; i < n; i++)
#define loop(i, s, n) for (int i = s; i < n; i++)
#define erep(e, v) for (auto &&e : v)
#define all(in) in.begin(), in.end()
#define MP make_pair
#define INF (sizeof(int) == 4 ? (int) 1e9 : (int) 1e18)
#define EPS 0.0000000001
using namespace std;
template <class T, class S> auto cmin(T &a, const S &b) {
    return (a > b ? a = b, true : false);
}
template <class T, class S> auto cmax(T &a, const S &b) {
    return (a < b ? a = b, true : false);
}
template <typename Head, typename Value>
auto vectors(const Head &head, const Value &v) {
    return vector<Value>(head, v);
}
template <typename Head, typename... Tail> auto vectors(Head x, Tail... tail) {
    auto inner = vectors(tail...);
    return vector<decltype(inner)>(x, inner);
}
template <class T> void join(T a) {
    for (auto itr : a) {
        if (itr != *a.begin()) cout << " ";
        cout << itr;
    }
}
using ld   = long double;
using pii  = pair<int, int>;
using piii = pair<int, pii>;
int W, H;
int dx[] = {0, 0, 1, -1}, dy[] = {1, -1, 0, 0};
bool valid(int x, int y) { return (0 <= x && x < W) && (0 <= y && y < H); }
main() {
    int n, m;
    while (cin >> n >> m, n + m) {
        map<int, int> mp;
        rep(i, n) {
            int d, v;
            cin >> d >> v;
            cmax(mp[d], v);
        }
        int ans = 0;
        for (auto itr : mp) ans += itr.second;
        cout << ans << endl;
    }
}