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)
}

Python: while 1:
    n,m=map(int,input().split())
    if n==m==0:break
    cont=[0]*(m+1)
    for i in range(n):
        d,v=map(int,input().split())
        if cont[d]<v:cont[d]=v
    print(sum(cont))

Python: while True:
  n,m=map(int,input().split())
  if n==0:exit()
  a=[0]*(m+1)
  for _ in range(n):
    d,v=map(int,input().split())
    a[d]=max(a[d],v)
  print(sum(a))

Python: m,n=map(int,input().split())
a =[]
for _ in range(m):
    a.append(list(map(int,input().split())))
for index in range(m):
    a[index].append(sum(a[index]))
for a_column in a:
    for num in a_column[:-1]:
        print(num, end=' ')
    print(a_column[-1])
for row_index in range(n+1):
    sum = 0
    for a_column in a:
        sum += a_column[row_index]
    print(sum, end=' ')
print()

Python: #d = むずかしさ, v = 推薦度
ans2 = []
while(1):
    tip = []
    tmp = []
    ans = 0
    n, m = map(int,input().split())
    if n == 0 and m == 0:
        break
    else:
        for i in range(n):
            d, v = map(int,input().split())
            tip.append([d, v])
        tip = sorted(tip, key = lambda x: x[1])
        tip.reverse()
        #print(tip)
        for i in range(n):
            if tip[i][0] in tmp:
                pass
            else:
                ans += tip[i][1]
                m += 1
                tmp.append(tip[i][0])
        #print("ans = {}".format(ans))
        ans2.append(ans)

for i in ans2:
    print(i)

Python: while True:
    line = input()

    if line == "0 0":
        break

    stock, max_difficulty = map(int, line.split(" "))

    max_recommend_list = [0 for _ in range(max_difficulty)]

    for i in range(stock):
        difficulty, recommend = map(int, input().split(" "))
        max_recommend_list[difficulty - 1] = max(max_recommend_list[difficulty - 1], recommend)

    print(sum(max_recommend_list))

Python: while 1:
    n, m = map(int, input().split())
    if n == 0:
        break

    rec = [0] * (m+1)
    for _ in range(n):
        d, v = map(int, input().split())
        if rec[d] < v:
            rec[d] = v

    print(sum(rec))

Python: while True:

    N,M = map(int,input().split())

    if N == 0 and M == 0:
        break
    
    ans = 0
    
    di = []
    vi = []

    for i in range(0,N):
        d,v = map(int,input().split())
        di.append(d)
        vi.append(v)
        
    for i in range(1,M+1):
        max = 0
        for j in range(0,N):
            if di[j] == i and max < vi[j]:
                max = vi[j]
        ans+=max

    print(ans)

Python: from collections import defaultdict
while True:
  n, m = map(int, input().split())
  if n == 0:break
  dic = defaultdict(int)
  for _ in range(n):
    d, v = map(int, input().split())
    dic[d] = max(dic[d], v)
  print(sum(dic.values()))

Python: while True:
    N,M=map(int,input().split())
    if N==0 and M==0:
        break
    l = [0]*M
    for i in range(N):
        d,v=map(int,input().split())
        if l[d-1]<v:
            l[d-1]=v
    total = 0
    for i in range(M):
        total += l[i]

    print(total)

Python: #21:40
#21:
while True:
    n,m = map(int,input().split())
    if n ==0 : break


    #難易度と最大推薦度の辞書
    question_dict={}

    for i in range(n):
        difficult,recommend = map(int,input().split())
        if difficult in question_dict:
            question_dict[difficult] = max(question_dict[difficult],recommend)
        else:
            question_dict[difficult] = recommend

    print(sum(question_dict.values()))

Python: while True:
    n, m = map(int, input().split())
    if not n and not m:
        break

    dataset = [0 for _ in range(m)]
    for i in range(n):
        d, v = map(int, input().split())
        dataset[d - 1] = max(v, dataset[d - 1])
    print(sum(dataset))

Python: m,n=map(int,input().split())
a =[]
for _ in range(m):
    a.append(list(map(int,input().split())))
for index in range(m):
    a[index].append(sum(a[index]))
for a_column in a:
    for num in a_column[:-1]:
        print(num, end=' ')
    print(a_column[-1])
for row_index in range(n+1):
    sum = 0
    for a_column in a:
        sum += a_column[row_index]
    print(sum, end=' ')
print()

Python: import sys

def solve(n, m):
    l = []
    for i in range(n):
        d, v = map(int, input().split())
        l.append((d, v))

    l.sort(reverse=True)

    now = -1
    count = 0
    for i in l:
        if now == i[0]:
            continue
        else:
            count += i[1]
            now = i[0]

    print(count)


while True:
    n, m = map(int, input().split())
    if n == m == 0:
        break
    solve(n, m)

Python: while 1:
    n, m = map(int, input().split())
    if n == 0:
        break
    s = [0]*(m+1)
    for _ in range(n):
        d, v = map(int, input().split())
        if s[d] < v:
            s[d] = v
    print(sum(s))

Python: "JAG模擬予選練習会"
while True:
    N, M = map(int, input().split())  # 問題の数N, 難易度の幅M
    if N == 0 and M == 0:
        break

    max_value = {}
    for i in range(1, M+1):
        max_value[i] = 0

    for i in range(N):
        d, v = map(int, input().split())
        max_value[d] = max(max_value[d], v)

    ans = sum(max_value.values())
    print(ans)

Python: while 1:
    n,m=map(int,input().split())
    if n==m==0:break
    s=set()
    c=0
    for d,v in sorted([list(map(int,input().split()))for i in range(n)],key=lambda x:-x[1]):
        if d in s:continue
        c+=v
        s.add(d)
        if len(s)>=m:
            break
    print(c)