import java.util.ArrayList;
import java.util.Iterator;
import java.util.Scanner;

public class Main{

    public static void main(String[] args) {
        Person pLast = new Person();
        pLast.id = -1;
        pLast.name = "";
        pLast.score = 0;
        ArrayList<Person> al = new ArrayList<Person>();
    ArrayList<Person> bl = new ArrayList<Person>();
    int number=0;
    Scanner in= new Scanner(System.in);
            int gametime=in.nextInt();
    for(int i = 0; i < gametime; i++)
        {
            Person p = new Person();
            p.id = number++;
            p.name = in.next();
            p.score = in.nextInt();

            Iterator<Person> iterator = al.iterator();
            while(iterator.hasNext())
            {
                Person pTest = iterator.next();
                if(p.name.equals(pTest.name))
                {
                    p.score = p.score + pTest.score;
                    iterator.remove();
                }
            }
            al.add(p);
            bl.add(p);
        }
    Iterator<Person> iterator = al.iterator();
        while(iterator.hasNext())
        {
            Person pTest = iterator.next();
//          System.out.println(pTest.id+"  "+pTest.name+"  "+pTest.score);
            if(pTest.score > pLast.score)
            {
                pLast = pTest;
            }
        }
        Iterator<Person> iteratorFlag = al.iterator();
        boolean flag=false;
        while(iteratorFlag.hasNext())
        {
            Person pTest = iteratorFlag.next();
            if(!pTest.name.equals(pLast.name) && pTest.score == pLast.score)
            {
                flag = true;
//              System.out.println(flag+"aaaa");
            }
        }
        if(flag)
        {
            ArrayList<String> name = new ArrayList<String>();
            Iterator<Person> iteratorA = al.iterator();
            while(iteratorA.hasNext())
            {
                Person pTest =  iteratorA.next();
                if(pTest.score == pLast.score)
                {
                    name.add(pTest.name);
                }
            }
            Iterator<Person> iteratorB = bl.iterator();
            while(iteratorB.hasNext())
            {
                Person pTest = iteratorB.next();
                Iterator<String> iteratorN = name.iterator();
                while (iteratorN.hasNext())
                {
                    String strName = iteratorN.next();
                    if (strName.equals(pTest.name) && pTest.score >= pLast.score)
                    {
                        System.out.println(pTest.name);
                        return;
                    }
                }
            }
        }
        System.out.println(pLast.name);
    }

}
      class Person
{
    int id;
    String name;
    int score;

//  int flag = 0;
}


import java.util.Scanner;

public class Main{

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int rounds = scan.nextInt();
        Wins[] records = new Wins[rounds + 1];
        Wins[] record2 = new Wins[rounds + 1];
        int maxscore = -99999;
        int index = 0;
        int size=0;
        for (int i = 0; i < rounds; i++) {
            String name = scan.next();
            int score = scan.nextInt();

            if (i == 0) {
                records[0] = new Wins(score, name);
                maxscore = score;
                size++;
            } else {
                boolean flage = false;
                for (int o = 0; o < size; o++) {

                    if (name.equals(records[o].name)) {
                        flage = true;
                        records[o].score = records[o].score + score;
                        if (maxscore < records[o].score) {
                            maxscore = records[o].score;
                            index = o;
                        }

                    }
                    if (flage) {
                        break;
                    }

                }
                if (!flage) {
                    records[i] = new Wins(score, name);
                    size++;
                    if (maxscore < score) {
                        maxscore = score;
                        index = i;
                    }

                }

            }
        }
        System.out.println(records[index].name);

    }
}

class Wins {

    int score;
    String name;
    int index;

    public Wins(int score, String name, int index) {
        this.score = score;
        this.name = name;
        this.index = index;
    }

    public Wins(int score, String name) {
        this.score = score;
        this.name = name;
        this.index = 0;
    }
}


import java.util.Scanner;

public class Main{

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int rounds = scan.nextInt();
        Wins[] records = new Wins[rounds + 1];
        Wins[] record2 = new Wins[rounds + 1];
        int maxscore = 0;
        int index = 0;
        for (int i = 0; i < rounds; i++) {
            String name = scan.next();
            int score = scan.nextInt();

            if (i == 0) {
                records[0] = new Wins(score, name);
                maxscore = score;
            } else {
                boolean flage = false;
                for (int o = 0; o <= i-1; o++) {

                    if (name.equals(records[o].name)) {
                        flage = true;
                        records[o].score = records[o].score + score;
                        if (maxscore < records[o].score) {
                            maxscore = records[o].score;
                            index = o;
                        }

                    }
                    if (flage) {
                        break;
                    }

                }
                if (!flage) {
                    records[i] = new Wins(score, name);
                    if (maxscore < score) {
                        maxscore = score;
                        index = i;
                    }

                }

            }
        }
        System.out.println(records[index].name);

    }
}

class Wins {

    int score;
    String name;
    int index;

    public Wins(int score, String name, int index) {
        this.score = score;
        this.name = name;
        this.index = index;
    }

    public Wins(int score, String name) {
        this.score = score;
        this.name = name;
        this.index = 0;
    }
}


import java.util.Scanner;
public class Main {

    public static void main(String[] args) {
Scanner scan=new Scanner(System.in);
int rounds=scan.nextInt();
Wins [] records=new Wins[rounds+1];
Wins [] record2=new Wins[rounds+1];
int maxscore=0;
int index=0;

     for (int i=0;i<rounds;i++)
        {
            String name=scan.next();
            int score=scan.nextInt();

            if(i==0){records[0]=new Wins(score,name);}
            else{
                boolean flag=false;
                for (int o=0;o<i;o++)
                {
                    if (flag)
                    {break;}
                    if(name.equals(records[o].name))
                    {
                        flag=true;
                        records[o].score=records[o].score+score;
                        if(maxscore<records[o].score)
                        {
                            maxscore=records[o].score;index=o;
                        }

                    }

                }
                    if (!flag) {records[i]=new Wins(score,name);}

                    }

        }System.out.println(records[index].name);
    }

    }

class Wins {
    int score;
    String name;
    int index;
    public Wins (int score,String name,int index)
    {
        this.score=score;
        this.name=name;
        this.index=index;
    }
    public Wins (int score,String name)
    {
        this.score=score;
        this.name=name;
        this.index=0;
    }
}


import java.util.Scanner;
public class Main {

    public static void main(String[] args) {
Scanner scan=new Scanner(System.in);
int rounds=scan.nextInt();
Wins [] records=new Wins[rounds+1];
Wins [] record2=new Wins[rounds+1];
int maxscore=0;
int index=0;
     for (int i=0;i<rounds;i++)
        {
            String name=scan.next();
            int score=scan.nextInt();

            if(i==0){records[0]=new Wins(score,name);}
            else{
                for (int o=0;o<=i;o++)
                {
                    if(name.equals(records[o].name))
                    {
                        records[o].score=records[o].score+score;
                        if(maxscore<records[o].score)
                        {
                            maxscore=records[o].score;index=o;
                        }

                    }
                    else{records[i]=new Wins(score,name);
                    if(maxscore<score)
                        {
                            maxscore=score;index=i;
                        }
                    }
                    break;

                }

        }}
        System.out.println(records[index].name);

    }
}
class Wins {
    int score;
    String name;
    int index;
    public Wins (int score,String name,int index)
    {
        this.score=score;
        this.name=name;
        this.index=index;
    }
    public Wins (int score,String name)
    {
        this.score=score;
        this.name=name;
        this.index=0;
    }
}


import java.util.Scanner;

public class Main{

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int rounds = scan.nextInt();
        Wins[] records = new Wins[rounds + 1];
        Wins[] record2 = new Wins[rounds + 1];
        int maxscore = -999999;
        int index = 0;
        int size=0;
        for (int i = 0; i < rounds; i++) {
            String name = scan.next();
            int score = scan.nextInt();

            if (i == 0) {
                records[0] = new Wins(score, name);
                maxscore = score;
                size++;
            } else {
                boolean flage = false;
                for (int o = 0; o < size; o++) {

                    if (name.equals(records[o].name)) {
                        flage = true;
                        records[o].score = records[o].score + score;
                        if (maxscore < records[o].score) {
                            maxscore = records[o].score;
                            index = o;
                        }

                    }
                    if (flage) {
                        break;
                    }

                }
                if (!flage) {
                    records[size] = new Wins(score, name);
                    size++;
                    if (maxscore < score) {
                        maxscore = score;
                        index = i;
                    }

                }

            }
        }
        System.out.println(records[index].name);

    }
}

class Wins {

    int score;
    String name;
    int index;

    public Wins(int score, String name, int index) {
        this.score = score;
        this.name = name;
        this.index = index;
    }

    public Wins(int score, String name) {
        this.score = score;
        this.name = name;
        this.index = 0;
    }
}


import java.util.Scanner;

public class Main{

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int rounds = scan.nextInt();
        Wins[] records = new Wins[rounds + 1];
        Wins[] record2 = new Wins[rounds + 1];
        int maxscore = 0;
        int index = 0;
        int size=0;
        for (int i = 0; i < rounds; i++) {
            String name = scan.next();
            int score = scan.nextInt();

            if (i == 0) {
                records[0] = new Wins(score, name);
                maxscore = score;
                size++;
            } else {
                boolean flage = false;
                for (int o = 0; o < size; o++) {

                    if (name.equals(records[o].name)) {
                        flage = true;
                        records[o].score = records[o].score + score;
                        if (maxscore < records[o].score) {
                            maxscore = records[o].score;
                            index = o;
                        }

                    }
                    if (flage) {
                        break;
                    }

                }
                if (!flage) {
                    records[i] = new Wins(score, name);
                    size++;
                    if (maxscore < score) {
                        maxscore = score;
                        index = i;
                    }

                }

            }
        }
        System.out.println(records[index].name);

    }
}

class Wins {

    int score;
    String name;
    int index;

    public Wins(int score, String name, int index) {
        this.score = score;
        this.name = name;
        this.index = index;
    }

    public Wins(int score, String name) {
        this.score = score;
        this.name = name;
        this.index = 0;
    }
}


import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
/**
 *
 * @author admin
 */
public class Main{

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int rounds = scan.nextInt();
        HashMap<String, Integer > HM = new HashMap<String, Integer>();

        int maxscore = -999999;
        int ms;
        int index = 0;
        int size = 0;
        String owner;
        String winner=null;
        for (int i = 0; i < rounds; i++) {
            String name = scan.next();
            int  score = scan.nextInt();
            if (i==0)
            {maxscore=score;
                 winner=name;
            }
            else
            {
            maxscore = Collections.max(HM.values());
            }
            if (HM.containsKey(name)) {

                int previos_score = HM.remove(name);

                    HM.put(name, score + previos_score);
                if(HM.get(name)>maxscore)
                {
                    winner=name;
                }

            } else {
                HM.put(name, score);

                if(HM.get(name)>maxscore)
                {
                    winner=name;
                }
            }

        }

System.out.println(winner);

    }
}


import java.util.*;
import java.io.*;

public class A {
    static final double eps = 1e-3;

    static Scanner sc = new Scanner(System.in);
    static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    static StreamTokenizer in = new StreamTokenizer(br);
    static PrintWriter out = new PrintWriter(System.out);

    public static void main(String[] args) throws IOException {
        String[] names = new String[1000];
        int[] scores = new int[1000];
        int[][] steps = new int[1000][2];

        in.nextToken();
        int n = (int)in.nval;
        int count = 0;
        for (int i = 0; i<n; i++){
            in.nextToken();
            String name = in.sval;
            int pos = 0;
            boolean f = false;
            for (int j = 0; j<count; j++)
                if (names[j].equals(name)){
                    pos = j;
                    f = true;
                    break;
                }
            if (!f){
                pos = count;
                names[count++] = name;
            }
            in.nextToken();
            int s = (int)in.nval;
            scores[pos] += s;
            steps[i][0] = pos;
            steps[i][1] = s;
        }
        int m = 0;
        for (int i = 0; i<count; i++)
            if (scores[i] > scores[m]) m = i;
        int xxx = scores[m];

        Arrays.fill(scores, 0);
        for (int i = 0; i<n; i++){
            int pos = steps[i][0];
            int s = steps[i][1];
            scores[pos] += s;
            if (scores[pos]>=xxx){
                m = pos;
                break;
            }
        }
        System.out.println(names[m]);
    }
}


import java.util.*;
import java.io.*;

public class A {
    static final double eps = 1e-3;

    static Scanner sc = new Scanner(System.in);
    static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    static StreamTokenizer in = new StreamTokenizer(br);
    static PrintWriter out = new PrintWriter(System.out);

    public static void main(String[] args) throws IOException {
        String[] names = new String[1000];
        int[] scores = new int[1000];
        int[][] steps = new int[1000][2];

        in.nextToken();
        int n = (int)in.nval;
        int count = 0;

        for (int i = 0; i<n; i++){
            in.nextToken();
            String name = in.sval;
            int pos = 0;
            boolean f = false;
            for (int j = 0; j<count; j++)
                if (names[j].equals(name)){
                    pos = j;
                    f = true;
                    break;
                }
            if (!f){
                pos = count;
                names[count++] = name;
            }

            in.nextToken();
            int s = (int)in.nval;
            scores[pos] += s;
            steps[i][0] = pos;
            steps[i][1] = s;
        }

        int m = 0;
        for (int i = 0; i<count; i++)
            if (scores[i] > scores[m]) m = i;
        int xxx = scores[m];
        boolean[] yes = new boolean[1000];

        Arrays.fill(scores, 0);
        for (int i = 0; i<n; i++){
            int pos = steps[i][0];
            int s = steps[i][1];
            scores[pos] += s;
            if (scores[pos]>=xxx){
                m = pos;
                yes[pos] = true;
            }
        }
        m = 0;
        for (int i = 0; i<count; i++)
            if (scores[i] == xxx && yes[i]){
                m = i;
                break;
            }
        System.out.println(names[m]);
    }
}


import java.util.*;
import java.io.*;

public class A {
	static final double eps = 1e-3;

	static Scanner sc = new Scanner(System.in);
	static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	static StreamTokenizer in = new StreamTokenizer(br);
	static PrintWriter out = new PrintWriter(System.out);

	public static class Gamer{
		public String name;
		public int score, max, id, step;

		public Gamer(String name, int id){
			this.name = name;
			this.id = id;
		}
	}

	public static void main(String[] args) throws IOException {
		int[][] steps = new int[1000][2];
		Gamer[] g = new Gamer[1000];

		in.nextToken();
		int n = (int)in.nval;
		int count = 0;

		for (int i = 0; i<n; i++){
			in.nextToken();
			String name = in.sval;
			int pos = 0;
			boolean f = false;
			for (int j = 0; j<count; j++)
				if (g[j].name.equals(name)){
					pos = j;
					f = true;
					break;
				}
			if (!f){
				pos = count;
				g[count++] = new Gamer(name, pos);
			}

			in.nextToken();
			int s = (int)in.nval;
			g[pos].score += s;
			steps[i][0] = pos;
			steps[i][1] = s;
		}

		int m = g[0].score;
		for (int i = 0; i<count; i++)
			if (g[i].score > m) m = g[i].score;

		for (int i = 0; i<count; i++)
			g[i].score = 0;

		for (int i = 0; i<n; i++){
			int pos = steps[i][0];
			int s = steps[i][1];
			g[pos].score += s;
			if (g[pos].score>=m){
				g[pos].step = i;
			}
		}

		int tt = 100000;
		int ans = 0;

		for (int i = 0; i<count; i++)
			if (g[i].score >= m && g[i].step<tt){
				tt = g[i].step;
				ans = i;
			}
		System.out.println(g[ans].name);
	}
}


import java.util.*;
import java.io.*;

public class A {
    static final double eps = 1e-3;

    static Scanner sc = new Scanner(System.in);
    static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    static StreamTokenizer in = new StreamTokenizer(br);
    static PrintWriter out = new PrintWriter(System.out);

    public static class Gamer{
        public String name;
        public int score, max, id, step;

        public Gamer(String name, int id){
            this.name = name;
            this.id = id;
        }
    }

    public static void main(String[] args) throws IOException {
        int[][] steps = new int[1000][2];
        Gamer[] g = new Gamer[1000];

        in.nextToken();
        int n = (int)in.nval;
        int count = 0;

        for (int i = 0; i<n; i++){
            in.nextToken();
            String name = in.sval;
            int pos = 0;
            boolean f = false;
            for (int j = 0; j<count; j++)
                if (g[j].name.equals(name)){
                    pos = j;
                    f = true;
                    break;
                }
            if (!f){
                pos = count;
                g[count++] = new Gamer(name, pos);
            }

            in.nextToken();
            int s = (int)in.nval;
            g[pos].score += s;
            steps[i][0] = pos;
            steps[i][1] = s;
        }

        int m = g[0].score;
        for (int i = 0; i<count; i++)
            if (g[i].score > m) m = g[i].score;

        for (int i = 0; i<count; i++){
            g[i].score = 0;
            g[i].step = -1;
        }

        for (int i = 0; i<n; i++){
            int pos = steps[i][0];
            int s = steps[i][1];
            g[pos].score += s;
            if (g[pos].score>=m && g[pos].step == -1){
                g[pos].step = i;
            }
        }

        int tt = 100000;
        int ans = 0;

        for (int i = 0; i<count; i++)
            if (g[i].score >= m && g[i].step<tt){
                tt = g[i].step;
                ans = i;
            }
        System.out.println(g[ans].name);
    }
}


import java.util.*;
import java.io.*;

public class A {
    static final double eps = 1e-3;

    static Scanner sc = new Scanner(System.in);
    static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    static StreamTokenizer in = new StreamTokenizer(br);
    static PrintWriter out = new PrintWriter(System.out);

    public static void main(String[] args) throws IOException {
        String[] names = new String[1000];
        int[] scores = new int[1000];
        int[] step = new int[1000];
        in.nextToken();
        int n = (int)in.nval;
        int count = 0;
        for (int i = 0; i<n; i++){
            in.nextToken();
            String name = in.sval;
            int pos = 0;
            boolean f = false;
            for (int j = 0; j<count; j++)
                if (names[j].equals(name)){
                    pos = j;
                    step[j] = i;
                    f = true;
                    break;
                }
            if (!f){
                pos = count;
                step[count] = i;
                names[count++] = name;
            }
            in.nextToken();
            scores[pos] += (int)in.nval;
        }
        int max = 0;
        for (int i = 0; i<count; i++)
            if (scores[i] > scores[max]) max = i;
            else if (scores[i] == scores[max] && step[i]<step[max]) max = i;
        System.out.println(names[max]);
    }
}


import java.util.*;
import java.io.*;

public class A {
    static final double eps = 1e-3;

    static Scanner sc = new Scanner(System.in);
    static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    static StreamTokenizer in = new StreamTokenizer(br);
    static PrintWriter out = new PrintWriter(System.out);

    public static void main(String[] args) throws IOException {
        String[] names = new String[1000];
        int[] scores = new int[1000];
        int[] step = new int[1000];
        int[] max = new int[1000];
        in.nextToken();
        int n = (int)in.nval;
        int count = 0;
        for (int i = 0; i<n; i++){
            in.nextToken();
            String name = in.sval;
            int pos = 0;
            boolean f = false;
            for (int j = 0; j<count; j++)
                if (names[j].equals(name)){
                    pos = j;
                    f = true;
                    break;
                }
            if (!f){
                pos = count;
                names[count++] = name;
            }
            in.nextToken();
            int s = (int)in.nval;
            scores[pos] += (int)in.nval;
            if (scores[pos]>max[pos]) {
                max[pos] = scores[pos];
                step[pos] = i;
            }
        }
        int m = 0;
        for (int i = 0; i<count; i++)
            if (max[i] > max[m]) m = i;
            else if (max[i] == max[m] && step[i]<step[m]) m = i;
        System.out.println(names[m]);
    }
}


import java.util.*;
import java.io.*;

public class A {
    static final double eps = 1e-3;

    static Scanner sc = new Scanner(System.in);
    static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    static StreamTokenizer in = new StreamTokenizer(br);
    static PrintWriter out = new PrintWriter(System.out);

    public static void main(String[] args) throws IOException {
        String[] names = new String[1000];
        int[] scores = new int[1000];
        int[] step = new int[1000];
        int[] max = new int[1000];
        in.nextToken();
        int n = (int)in.nval;
        int count = 0;
        for (int i = 0; i<n; i++){
            in.nextToken();
            String name = in.sval;
            int pos = 0;
            boolean f = false;
            for (int j = 0; j<count; j++)
                if (names[j].equals(name)){
                    pos = j;
                    f = true;
                    break;
                }
            if (!f){
                pos = count;
                names[count++] = name;
            }
            in.nextToken();
            int s = (int)in.nval;
            scores[pos] += (int)in.nval;
            if (scores[pos]>max[pos]) {
                max[pos] = scores[pos];
                step[pos] = i;
            }
        }
        int m = 0;
        for (int i = 0; i<count; i++)
            if (scores[i] > scores[m]) m = i;
            else if (scores[i] == scores[m] && step[i]<step[m]) m = i;
        System.out.println(names[m]);
    }
}


import java.util.*;
import java.io.*;/* codeforces #2 */

public class A {
	public static void main(String[] args) throws Exception {
		new A().solve(new BufferedReader(new InputStreamReader(System.in)),
				new PrintWriter(System.out));
	}

	public void solve(Reader in, PrintWriter out) {
		Scanner s = new Scanner(in);
		Map<String, Integer>map =new HashMap<String, Integer>();
		List<String> list = new ArrayList<String>();
		for(int n=s.nextInt();n-->0;){
			String name = s.next(), point = s.next();
			list.add(name + " " + point);
			Integer count = map.get(name);
			if(count == null){
				count = 0;
			}
			map.put(name , count + new Integer(point));
		}
		int max = Collections.max(map.values());
		map =new HashMap<String, Integer>();
		for(String next : list){
			String[] sp = next.split(" ");
			Integer count = map.get(sp[0]);
			if(count == null){
				count = 0;
			}
			map.put(sp[0] , count + new Integer(sp[1]));
			if(map.get(sp[0])==max){
				out.println(sp[0]);
				break;
			}
		}
		out.close();
	}

}


import java.util.*;

public class A {
	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		int n = s.nextInt();
		String[] names = new String[n];
		int[] scores = new int[n];
		Map<String, Integer> map = new HashMap<String, Integer>();
		for (int i = 0; i < n; ++i) {
			names[i] = s.next();
			scores[i] = s.nextInt();
			Integer c = map.get(names[i]);
			if (c == null) {
				c = 0;
			}
			map.put(names[i], c + scores[i]);
		}
		int max = Collections.max(map.values());
		String result = "";
		Set<String> set = new HashSet<String>();
		for (String key : map.keySet()) {
			if (map.get(key) == max) {
				set.add(key);
			}
		}
		map = new HashMap<String, Integer>();
		for (String name : names) {
			map.put(name, 0);
		}
		for (int i = 0; i < n; ++i) {
			if (set.contains(names[i])) {
				int value = map.get(names[i]) + scores[i];
				if (value >= max) {
					result = names[i];
					break;
				}
				map.put(names[i], value);
			}
		}
		System.out.println(result);
	}
}


import java.util.*;
import java.io.*;/* codeforces #2 */

public class A {
	public static void main(String[] args) throws Exception {
		new A().solve(new BufferedReader(new InputStreamReader(System.in)),
				new PrintWriter(System.out));
	}

	public void solve(Reader in, PrintWriter out) {
		Scanner s = new Scanner(in);
		List<C> list = new ArrayList<C>();
		Map<String, Integer>map =new HashMap<String, Integer>();
		int max = 0;
		for(int n=s.nextInt();n-->0;){
			C e = new C(s.next(),s.nextInt());
			list.add(e);
			Integer count = map.get(e.name);
			if(count == null){
				count = 0;
			}
			max = Math.max(max, e.point += count);
			map.put(e.name , e.point);
		}
		for(C c : list){
			if(c.point == max){
				out.println(c.name);
				break;
			}
		}
		out.close();
	}

	class C{
		String name;
		int point;
		public C(String name, int point) {
			this.name = name;
			this.point = point;
		}
	}
}


import java.util.*;
import java.io.*;/* codeforces #2 */

public class A {
	public static void main(String[] args) throws Exception {
		new A().solve(new BufferedReader(new InputStreamReader(System.in)),
				new PrintWriter(System.out));
	}

	public void solve(Reader in, PrintWriter out) {
		Scanner s = new Scanner(in);
		Map<String, Integer>map =new HashMap<String, Integer>();
		List<String> list = new ArrayList<String>();
		for(int n=s.nextInt();n-->0;){
			String name = s.next(), point = s.next();
			list.add(name + " " + point);
			Integer count = map.get(name);
			if(count == null){
				count = 0;
			}
			map.put(name , count + new Integer(point));
		}
		int max = Collections.max(map.values());
		map =new HashMap<String, Integer>();
		for(String next : list){
			String[] sp = next.split(" ");
			Integer count = map.get(sp[0]);
			if(count == null){
				count = 0;
			}
			map.put(sp[0] , count + new Integer(sp[1]));
			if(map.get(sp[0])>=max){
				out.println(sp[0]);
				break;
			}
		}
		out.close();
	}

}


import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;

public class A {

	public static void main(String[] args) {
		new A().solve();
	}

	public void solve(){
		Scanner s = new Scanner(System.in);
		int n = s.nextInt();
		FreqCount<String> freq = new FreqCount<String>();
		for(;n-->0;){
			freq.add(s.next(), s.nextInt());
		}
		System.out.println(freq.maxValues().get(0));
		s.close();
	}
	static class FreqCount<T> {
		Map<T, Integer> map = new HashMap<T, Integer>();
		int max = 0, min = Integer.MAX_VALUE;

		void add(T t, int p) {
			Integer c = map.get(t);
			if (c == null) {
				c = 0;
			}
			c+=p;
			map.put(t, c);
			max = Math.max(max, c);
			min = Math.min(min, c);
		}

		List<T> maxValues() {
			List<T> list = new ArrayList<T>();
			for (T t : map.keySet()) {
				if (map.get(t) == max) {
					list.add(t);
				}
			}
			return list;
		}

		List<T> minValue() {
			List<T> list = new ArrayList<T>();
			for (T t : map.keySet()) {
				if (map.get(t) == min) {
					list.add(t);
				}
			}
			return list;
		}
	}
}


import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;

public class A {

	public static void main(String[] args) {
		new A().solve();
	}

	public void solve() {
		Scanner s = new Scanner(System.in);
		int n = s.nextInt(), max = 0;
		List<String> names = new ArrayList<String>();
		Map<String, Integer> map = new HashMap<String, Integer>();
		for (; n-- > 0;) {
			String name = s.next();
			Integer count = map.get(name);
			if(map.containsKey(name)){
				count = 0;
			}
			count += s.nextInt();
			max = Math.max(max, count);
			map.put(name, count);
		}
		for(String name : names){
			if(map.get(name)==max){
				System.out.println(name);
			}
		}
	}
}


import java.util.*;

public class A {
	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		int n = s.nextInt();
		String[] names = new String[n];
		int[] scores = new int[n];
		for (int i = 0; i < n; ++i) {
			names[i] = s.next();
			scores[i] = s.nextInt();
		}
		Map<String, Integer> map = new HashMap<String, Integer>(), map2;
		for (String name : names) {
			map.put(name, 0);
		}
		map2 = new HashMap<String, Integer>(map);
		for (int i = 0; i < n; ++i) {
			map.put(names[i], map.get(names[i]) + scores[i]);
		}
		int max = Collections.max(map.values());
		String result = "";
		for (int i = 0; i < n; ++i) {
			int value = map2.get(names[i]) + scores[i];
			if (value >= max) {
				result = names[i];
				break;
			}
			map2.put(names[i], value);
		}
		System.out.println(result);
	}
}


import java.util.*;

public class A {
	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		int n = s.nextInt();
		String[] names = new String[n];
		int[] scores = new int[n];
		for (int i = 0; i < n; ++i) {
			names[i] = s.next();
			scores[i] = s.nextInt();
		}
		Map<String, Integer> map = new HashMap<String, Integer>(), map2;
		for (String name : names) {
			map.put(name, 0);
		}
		map2 = new HashMap<String, Integer>(map);
		for (int i = 0; i < n; ++i) {
			map.put(names[i], map.get(names[i]) + scores[i]);
		}
		int max = Collections.max(map.values());
		String result = "";
		for (int i = 0; i < n; ++i) {
			int value = map2.get(names[i]) + scores[i];
			if (value == max) {
				result = names[i];
				break;
			}
			map2.put(names[i], value);
		}
		System.out.println(result);
	}
}


import java.util.*;

public class A {
	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		int n = s.nextInt();
		String[] names = new String[n];
		int[] scores = new int[n];
		Map<String, Integer> map = new HashMap<String, Integer>();
		for (String name : names) {
			map.put(name, 0);
		}
		for (int i = 0; i < n; ++i) {
			names[i] = s.next();
			scores[i] = s.nextInt();
			Integer c = map.get(names[i]);
			if (c == null) {
				c = 0;
			}
			map.put(names[i], c + scores[i]);
		}
		int max = Collections.max(map.values());
		String result = "";
		Map<String, Integer> map2 = new HashMap<String, Integer>();
		for (String name : names) {
			map2.put(name, 0);
		}
		for (int i = 0; i < n; ++i) {
			int value = map2.get(names[i]) + scores[i];
			if (value >= max) {
				result = names[i];
				break;
			}
			map2.put(names[i], value);
		}
		System.out.println(result);
	}
}


import java.util.*;

public class A {
	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		int n = s.nextInt();
		String[] names = new String[n];
		int[] scores = new int[n];
		for (int i = 0; i < n; ++i) {
			names[i] = s.next();
			scores[i] = s.nextInt();
		}
		Map<String, Integer> map = new HashMap<String, Integer>(), map2;
		for (String name : names) {
			map.put(name, 0);
		}
		map2 = new HashMap<String, Integer>(map);
		for (int i = 0; i < n; ++i) {
			map.put(names[i], map.get(names[i]) + scores[i]);
		}
		int max = Collections.max(map.values());
		String result = "";
		for (int i = 0; i < n; ++i) {
			int value = map2.get(names[i]) + scores[i];
			if (value == max) {
				result = names[i];
				break;
			}
			map2.put(names[i], value);
		}
		System.out.println(max>=0?result:"");
	}
}


import java.util.*;

public class A {
	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		int n = s.nextInt();
		String[] names = new String[n];
		int[] scores = new int[n];
		Map<String, Integer> map = new HashMap<String, Integer>();
		for (int i = 0; i < n; ++i) {
			names[i] = s.next();
			scores[i] = s.nextInt();
			Integer c = map.get(names[i]);
			if (c == null) {
				c = 0;
			}
			map.put(names[i], c + scores[i]);
		}
		int max = Collections.max(map.values());
		String result = "";
		map = new HashMap<String, Integer>();
		for (String name : names) {
			map.put(name, 0);
		}
		for (int i = 0; i < n; ++i) {
			int value = map.get(names[i]) + scores[i];
			if (value >= max) {
				result = names[i];
				break;
			}
			map.put(names[i], value);
		}
		System.out.println(result);
	}
}


import java.util.LinkedList;
import java.util.HashMap;
import java.util.Scanner;

public class Winner {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);

        LinkedList<String> names = new LinkedList<String>();
        HashMap<String, Integer> timeMap = new HashMap<String, Integer>();
        HashMap<String, Integer> scoreMap = new HashMap<String, Integer>();

        int n = scan.nextInt();
        for (int i = 0; i < n; i++) {
            String name = scan.next();
            int score = scan.nextInt();

            Integer old = scoreMap.get(name);
            if (old == null) {
                scoreMap.put(name, score);
                names.add(name);
            } else {
                scoreMap.put(name, old + score);
            }
            timeMap.put(name, i);
        }

        int maxScore = Integer.MIN_VALUE;
        int maxTime = Integer.MAX_VALUE;
        String maxName = null;
        for (String name : names) {
            int time = timeMap.get(name);
            int score = scoreMap.get(name);
            if (score > maxScore || (score == maxScore && time < maxTime)) {
                maxScore = score;
                maxName = name;
                maxTime = time;
            }
        }
        System.out.println(maxName);
    }
}


import java.util.LinkedList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Scanner;

public class Winner {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);

        int n = scan.nextInt();
        int[] score = new int[n];
        String[] names = new String[n];
        HashMap<String, Integer> scoreMap = new HashMap<String, Integer>();

        for (int i = 0; i < n; i++) {
            names[i] = scan.next();
            score[i] = scan.nextInt();

            Integer old = scoreMap.get(names[i]);
            if (old == null) {
                scoreMap.put(names[i], score[i]);
            } else {
                scoreMap.put(names[i], old + score[i]);
            }
        }

        int maxScore = scoreMap.get(names[0]);
        for (int s : scoreMap.values())
            maxScore = Math.max(s, maxScore);

        HashSet<String> winners = new HashSet<String>();
        for (Map.Entry<String, Integer> entry : scoreMap.entrySet())
            if (entry.getValue() == maxScore)
                winners.add(entry.getKey());

        scoreMap.clear();
        for (int i = 0; i < n; i++) {
            if (!winners.contains(names[i]))
                continue;

            Integer old = scoreMap.get(names[i]);
            if (old == null) {
                if (score[i] == maxScore) {
                    System.out.println(names[i]);
                    break;
                }
                scoreMap.put(names[i], score[i]);
            } else {
                if (old + score[i] == maxScore) {
                    System.out.println(names[i]);
                    break;
                }
                scoreMap.put(names[i], old + score[i]);
            }
        }
    }
}


import java.util.HashMap;
import java.util.Scanner;

public class Winner {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);

        int maxScore = 0;
        String maxName = null;
        HashMap<String, Integer> map = new HashMap<String, Integer>();

        int n = scan.nextInt();
        for (int i = 0; i < n; i++) {
            String name = scan.next();
            int score = scan.nextInt();

            Integer old = map.get(name);
            if (old == null) {
                map.put(name, score);
                if (score > maxScore) {
                    maxScore = score;
                    maxName = name;
                }
            } else {
                map.put(name, old + score);
                if (old + score > maxScore) {
                    maxScore = old + score;
                    maxName = name;
                }
            }
        }

        System.out.println(maxName);
    }
}


import java.util.LinkedList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Scanner;

public class Winner {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);

        int n = scan.nextInt();
        int[] score = new int[n];
        String[] names = new String[n];
        HashMap<String, Integer> scoreMap = new HashMap<String, Integer>();

        for (int i = 0; i < n; i++) {
            names[i] = scan.next();
            score[i] = scan.nextInt();

            int old = (scoreMap.containsKey(names[i]) ? scoreMap.get(names[i]) : 0);
            scoreMap.put(names[i], old + score[i]);
        }

        int maxScore = scoreMap.get(names[0]);
        for (int s : scoreMap.values())
            maxScore = Math.max(s, maxScore);

        HashMap<String, Integer> winnerMap = new HashMap<String, Integer>();
        for (int i = 0; i < n; i++) {
            if (scoreMap.get(names[i]) != maxScore)
                continue;

            int old = (winnerMap.containsKey(names[i]) ? winnerMap.get(names[i]) : 0);
            if (old + score[i] >= maxScore) {
                System.out.println(names[i]);
                break;
            }
            winnerMap.put(names[i], old + score[i]);
        }
    }
}


import java.util.HashMap;
import java.util.LinkedList;
import java.util.Scanner;

public class Winner {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);

        LinkedList<String> insertionOrder = new LinkedList<String>();
        HashMap<String, Integer> map = new HashMap<String, Integer>();

        int n = scan.nextInt();
        for (int i = 0; i < n; i++) {
            String name = scan.next();
            int score = scan.nextInt();

            Integer old = map.get(name);
            if (old == null) {
                map.put(name, score);
                insertionOrder.add(name);
            } else {
                map.put(name, old + score);
            }
        }

        int maxScore = Integer.MIN_VALUE;
        String maxName = null;
        for (String name : insertionOrder) {
            int score = map.get(name);
            if (score > maxScore) {
                maxScore = score;
                maxName = name;
            }
        }
        System.out.println(maxName);
    }
}


import java.util.TreeMap;
import java.util.Scanner;

public class Winner {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);

        TreeMap<String, Integer> map = new TreeMap<String, Integer>();

        int n = scan.nextInt();
        for (int i = 0; i < n; i++) {
            String name = scan.next();
            int score = scan.nextInt();

            Integer old = map.get(name);
            if (old == null) {
                map.put(name, score);
            } else {
                map.put(name, old + score);
            }
        }

        int maxScore = Integer.MIN_VALUE;
        String maxName = null;
        for (String name : map.keySet()) {
            int score = map.get(name);
            if (score > maxScore) {
                maxScore = score;
                maxName = name;
            }
        }
        System.out.println(maxName);
    }
}


import java.util.LinkedList;
import java.util.HashMap;
import java.util.Scanner;

public class Winner {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);

        LinkedList<String> names = new LinkedList<String>();
        HashMap<String, Integer> timeMap = new HashMap<String, Integer>();
        HashMap<String, Integer> scoreMap = new HashMap<String, Integer>();

        int n = scan.nextInt();
        for (int i = 0; i < n; i++) {
            String name = scan.next();
            int score = scan.nextInt();

            Integer old = scoreMap.get(name);
            if (old == null) {
                scoreMap.put(name, score);
                names.add(name);
            } else {
                scoreMap.put(name, old + score);
            }
            if (score > 0 || timeMap.get(name) == null)
                timeMap.put(name, i);
        }

        int maxScore = Integer.MIN_VALUE;
        int maxTime = Integer.MAX_VALUE;
        String maxName = null;
        for (String name : names) {
            int time = timeMap.get(name);
            int score = scoreMap.get(name);
            if (score > maxScore || (score == maxScore && time < maxTime)) {
                maxScore = score;
                maxName = name;
                maxTime = time;
            }
        }
        System.out.println(maxName);
    }
}


import java.util.LinkedList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Scanner;

public class Winner {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);

        int n = scan.nextInt();
        int[] score = new int[n];
        String[] names = new String[n];
        HashMap<String, Integer> scoreMap = new HashMap<String, Integer>();

        for (int i = 0; i < n; i++) {
            names[i] = scan.next();
            score[i] = scan.nextInt();

            Integer old = scoreMap.get(names[i]);
            if (old == null) {
                scoreMap.put(names[i], score[i]);
            } else {
                scoreMap.put(names[i], old + score[i]);
            }
        }

        int maxScore = scoreMap.get(names[0]);
        for (int s : scoreMap.values())
            maxScore = Math.max(s, maxScore);

        HashSet<String> winners = new HashSet<String>();
        for (Map.Entry<String, Integer> entry : scoreMap.entrySet())
            if (entry.getValue() == maxScore)
                winners.add(entry.getKey());

        scoreMap.clear();
        for (int i = 0; i < n; i++) {
            if (!winners.contains(names[i]))
                continue;

            Integer old = scoreMap.get(names[i]);
            if (old == null) {
                if (score[i] >= maxScore) {
                    System.out.println(names[i]);
                    break;
                }
                scoreMap.put(names[i], score[i]);
            } else {
                if (old + score[i] >= maxScore) {
                    System.out.println(names[i]);
                    break;
                }
                scoreMap.put(names[i], old + score[i]);
            }
        }
    }
}


import java.util.LinkedList;
import java.util.HashMap;
import java.util.Scanner;

public class Winner {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);

        LinkedList<String> names = new LinkedList<String>();
        HashMap<String, Integer> timeMap = new HashMap<String, Integer>();
        HashMap<String, Integer> scoreMap = new HashMap<String, Integer>();

        int n = scan.nextInt();
        for (int i = 0; i < n; i++) {
            String name = scan.next();
            int score = scan.nextInt();

            Integer old = scoreMap.get(name);
            if (old == null) {
                scoreMap.put(name, score);
                names.add(name);
            } else {
                scoreMap.put(name, old + score);
            }
            if (score > 0)
                timeMap.put(name, i);
        }

        int maxScore = Integer.MIN_VALUE;
        int maxTime = Integer.MAX_VALUE;
        String maxName = null;
        for (String name : names) {
            int time = timeMap.get(name);
            int score = scoreMap.get(name);
            if (score > maxScore || (score == maxScore && time < maxTime)) {
                maxScore = score;
                maxName = name;
                maxTime = time;
            }
        }
        System.out.println(maxName);
    }
}


import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
/**
 *
 * @author user
 */
public class Main {

    /**
     * @param args
     *            the command line arguments
     */
    static int max = Integer.MIN_VALUE;
    static String res = "";
    static int t;

    public static void main(String[] args) {

        try {
            BufferedReader reader = new BufferedReader(new InputStreamReader(
                    System.in));

            int test = Integer.parseInt(reader.readLine());

            Map<String, Integer[]> data = new TreeMap<String, Integer[]>();

            while (test-- > 0) {
                t = test;
                String[] line = reader.readLine().split(" ");

                if (!data.containsKey(line[0])) {
                    Integer[] arr = new Integer[2];

                    arr[0] = Integer.parseInt(line[1]);
                    arr[1] = test;
                    data.put(line[0], arr);
                    getMax(data);

                } else {
                    getMax(data);
                    Integer[] aa = data.get(line[0]);
                    if (res.equals(line[0]) && Integer.parseInt(line[1]) < 0) {
                        max += Integer.parseInt(line[1]);
                        t = aa[1];
                        getMax(data);
                        if (res.equals(line[0])) {
                            aa[0] += Integer.parseInt(line[1]);
                            aa[1] = t;
                            data.put(line[0], aa);
                        }
                    }

                    else {
                        aa[0] += Integer.parseInt(line[1]);
                        aa[1] = test;
                        data.put(line[0], aa);
                    }

                }

            }
            getMax(data);
            System.out.println(res);

            reader.close();
        } catch (Exception e) {
        }

    }

    private static void getMax(Map<String, Integer[]> data) {

        Set<String> names = data.keySet();

        Iterator it = names.iterator();

        while (it.hasNext()) {
            String temp = (String) it.next();
            Integer[] aa = data.get(temp);

            if (aa[0] > max || (aa[0] == max && aa[1] > t)) {
                res = temp;
                max = aa[0];
                t = aa[1];
            }

        }

    }
}


import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
/**
 *
 * @author user
 */
public class Main {

    /**
     * @param args
     *            the command line arguments
     */

    static String res = "";

    public static void main(String[] args) {

        try {
            BufferedReader reader = new BufferedReader(new InputStreamReader(
                    System.in));

            int test = Integer.parseInt(reader.readLine());
            String[] names = new String[test];
            int score[] = new int[test];
            Map<String, Integer> data = new TreeMap<String, Integer>();

            for (int i = 0; i < test; i++) {

                String[] line = reader.readLine().split(" ");
                names[i] = line[0];
                score[i] = Integer.parseInt(line[1]);

                if (!data.containsKey(line[0])) {

                    data.put(line[0], Integer.parseInt(line[1]));

                } else {

                    data.put(line[0],
                            data.get(line[0]) + Integer.parseInt(line[1]));

                }

            }
            getMax(data, names, score);
            System.out.println(res);

            reader.close();
        } catch (Exception e) {
        }

    }

    private static void getMax(Map<String, Integer> data, String[] name,
            int[] score) {
        int max = Integer.MIN_VALUE;
        List<String> safaa = new ArrayList<String>();
        Set<String> names = data.keySet();

        Iterator it = names.iterator();

        while (it.hasNext()) {
            String temp = (String) it.next();
            Integer aa = data.get(temp);

            if (aa >= max) {

                max = aa;

            }

        }
        names = data.keySet();

        it = names.iterator();

        while (it.hasNext()) {
            String temp = (String) it.next();
            Integer aa = data.get(temp);

            if (aa == max) {

                safaa.add(temp);

            }

        }
        int array[] = new int[safaa.size()];
        for (int i = 0; i < safaa.size(); i++) {

            int sum = 0;
            String player = safaa.get(i);
            for (int c = 0; c < score.length; c++) {
                if (name[c].equals(player)) {

                    if (sum >= max && (sum += score[c]) >= max)
                        continue;

                    if (sum == max) {

                        array[i] = c;
                    }
                }
            }
        }

        int min = score.length;
        int index = 0;
        for (int i = 0; i < array.length; i++) {

            if (array[i] < min) {
                min = array[i];
                index = i;
            }
        }

        res = safaa.get(index);

    }
}


import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
/**
 *
 * @author user
 */
public class Main {

    /**
     * @param args
     *            the command line arguments
     */

    static String res = "";

    public static void main(String[] args) {

        try {
            BufferedReader reader = new BufferedReader(new InputStreamReader(
                    System.in));

            int test = Integer.parseInt(reader.readLine());
            String[] names = new String[test];
            int score[] = new int[test];
            Map<String, Integer> data = new TreeMap<String, Integer>();

            for (int i = 0; i < test; i++) {

                String[] line = reader.readLine().split(" ");
                names[i] = line[0];
                score[i] = Integer.parseInt(line[1]);

                if (!data.containsKey(line[0])) {

                    data.put(line[0], Integer.parseInt(line[1]));

                } else {

                    data.put(line[0],
                            data.get(line[0]) + Integer.parseInt(line[1]));

                }

            }
            getMax(data, names, score);
            System.out.println(res);

            reader.close();
        } catch (Exception e) {
        }

    }

    private static void getMax(Map<String, Integer> data, String[] name,
            int[] score) {
        int max = Integer.MIN_VALUE;
        List<String> safaa = new ArrayList<String>();
        Set<String> names = data.keySet();

        Iterator it = names.iterator();

        while (it.hasNext()) {
            String temp = (String) it.next();
            Integer aa = data.get(temp);

            if (aa >= max) {

                max = aa;

            }

        }
        names = data.keySet();

        it = names.iterator();

        while (it.hasNext()) {
            String temp = (String) it.next();
            Integer aa = data.get(temp);

            if (aa == max) {

                safaa.add(temp);

            }

        }
        int array[] = new int[safaa.size()];
        for (int i = 0; i < safaa.size(); i++) {

            int sum = 0;
            int t = 0;
            String player = safaa.get(i);
            for (int c = 0; c < score.length; c++) {
                if (name[c].equals(player)) {
                    sum = sum + score[c];
                    /*//System.out.println(c+" "+sum+" "+t);
                    if (sum >= max && t >= max) {

                        sum = t;
                        continue;
                    }
                    sum = t;*/

                    if (sum >= max) {

                        array[i] = c;
                        break;
                    }
                }
            }
        }

        int min = score.length;
        int index = 0;
        for (int i = 0; i < array.length; i++) {

            if (array[i] < min) {
                min = array[i];
                index = i;
            }
        }

        res = safaa.get(index);

    }
}


import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
/**
 *
 * @author user
 */
public class Main {

    /**
     * @param args
     *            the command line arguments
     */

    static String res = "";

    public static void main(String[] args) {

        try {
            BufferedReader reader = new BufferedReader(new InputStreamReader(
                    System.in));

            int test = Integer.parseInt(reader.readLine());
            String[] names = new String[test];
            int score[] = new int[test];
            Map<String, Integer> data = new TreeMap<String, Integer>();

            for (int i = 0; i < test; i++) {

                String[] line = reader.readLine().split(" ");
                names[i] = line[0];
                score[i] = Integer.parseInt(line[1]);

                if (!data.containsKey(line[0])) {

                    data.put(line[0], Integer.parseInt(line[1]));

                } else {

                    data.put(line[0],
                            data.get(line[0]) + Integer.parseInt(line[1]));

                }

            }
            getMax(data, names, score);
            System.out.println(res);

            reader.close();
        } catch (Exception e) {
        }

    }

    private static void getMax(Map<String, Integer> data, String[] name,
            int[] score) {
        int max = Integer.MIN_VALUE;
        List<String> safaa = new ArrayList<String>();
        Set<String> names = data.keySet();

        Iterator it = names.iterator();

        while (it.hasNext()) {
            String temp = (String) it.next();
            Integer aa = data.get(temp);

            if (aa >= max) {

                max = aa;

            }

        }
        names = data.keySet();

        it = names.iterator();

        while (it.hasNext()) {
            String temp = (String) it.next();
            Integer aa = data.get(temp);

            if (aa == max) {

                safaa.add(temp);

            }

        }
        int array[] = new int[safaa.size()];
        for (int i = 0; i < safaa.size(); i++) {
            int sum = 0;
            String player = safaa.get(i);
            for (int c = 0; c < score.length; c++) {
                if (name[c].equals(player)) {
                    sum += score[c];
                    if (sum == max) {
                        array[i] = c;
                    }
                }
            }
        }

        int min = score.length;
        int index = 0;
        for (int i = 0; i < array.length; i++) {

            if (array[i] < min) {
                min = array[i];
                index = i;
            }
        }

        res = safaa.get(index);

    }
}


import java.util.Scanner;

public class Winner {

	public static void main(String[] args) {
		int n, i, d, c, j;
		String s;
		Scanner cin=new Scanner(System.in);
		n = cin.nextInt();

		String []name  = new String [n];
		int []score = new int[n];
		int max=Integer.MIN_VALUE, k=-1;
		for(i=0 ; i<n ; i++){
			name[i] = cin.next();
			score[i] = cin.nextInt();
		}

		String []Name  = new String [n];
		int []Score = new int[n];

		int num=0;
		for(i=0 ; i<n ; i++){
			for(j=0; j<num; j++) if(name[i].hashCode()==Name[j].hashCode()) break;
			if(j==num){
				Name[num] = name[i];
				Score[num] = score[i];
				num ++;
			}
			else{
				Score[j] += score[i];
			}
		}

		for(i=0 ; i<num ; i++){
			if(max<score[i]){
				max=score[i];
			}
		}

		num=0;
		for(i=0 ; i<n ; i++){
			for(j=0; j<num; j++) if(name[i].hashCode()==Name[j].hashCode()) break;
			if(j==num){
				Name[num] = name[i];
				Score[num] = score[i];
				if(Score[num]>=max){
					k = num;
					i=n;
					j=n;
				}
				num ++;
			}
			else{
				Score[j] += score[i];
				if(Score[j]>=max){
					k = j;
					i=n;
					j=n;
				}
			}
		}

		System.out.println(Name[k]);
	}

}


import java.util.Scanner;

public class Winner {

	public static void main(String[] args) {
		int n, i, j;
		Scanner cin=new Scanner(System.in);
		n = cin.nextInt();

		String []name  = new String [n];
		int []score = new int[n];
		int max=Integer.MIN_VALUE, k=-1;
		for(i=0 ; i<n ; i++){
			name[i] = cin.next();
			score[i] = cin.nextInt();
		}

		String []Name  = new String [n];
		int []Score = new int[n];

		int num=0;
		for(i=0 ; i<n ; i++){
			for(j=0; j<num; j++) if(name[i].hashCode()==Name[j].hashCode()){
				if(name[i].equals(Name[j])) break;
			}
			if(j==num){
				Name[num] = name[i];
				Score[num] = score[i];
				num ++;
			}
			else{
				Score[j] += score[i];
			}
		}

		for(i=0 ; i<num ; i++){
			if(max<score[i]){
				max=score[i];
			}
		}

		num=0;
		for(i=0 ; i<n ; i++){
			for(j=0; j<num; j++) if(name[i].hashCode()==Name[j].hashCode()){
				if(name[i].equals(Name[j])) break;
			}
			if(j==num){
				Name[num] = name[i];
				Score[num] = score[i];
				if(Score[num]>=max){
					k = num;
					i=n;
					j=n;
				}
				num ++;
			}
			else{
				Score[j] += score[i];
				if(Score[j]>=max){
					k = j;
					i=n;
					j=n;
				}
			}
		}

		System.out.println(Name[k]);
	}

}


import java.util.Scanner;

public class Winner {

	public static void main(String[] args) {
		int n, i, j;
		Scanner cin=new Scanner(System.in);
		n = cin.nextInt();

		String []name  = new String [n];
		int []score = new int[n];
		int max=Integer.MIN_VALUE, k=-1;
		for(i=0 ; i<n ; i++){
			name[i] = cin.next();
			score[i] = cin.nextInt();
		}

		String []Name  = new String [n];
		int []Score = new int[n];

		int num=0;
		for(i=0 ; i<n ; i++){
			for(j=0; j<num; j++) if(name[i].hashCode()==Name[j].hashCode()){
				if(name[i].equals(Name[j])) break;
			}
			if(j==num){
				Name[num] = name[i];
				Score[num] = score[i];
				num ++;
			}
			else{
				Score[j] += score[i];
			}
		}

		for(i=0 ; i<num ; i++){
			if(max<Score[i]){
				max=Score[i];
			}
		}

		num=0;
		for(i=0 ; i<n ; i++){
			for(j=0; j<num; j++) if(name[i].hashCode()==Name[j].hashCode()){
				if(name[i].equals(Name[j])) break;
			}
			if(j==num){
				Name[num] = name[i];
				Score[num] = score[i];
				if(Score[num]>=max && score[num]==max){
					k = num;
					i=n;
				}
				num ++;
			}
			else{
				Score[j] += score[i];
				if(Score[j]>=max && score[num]==max){
					k = j;
					i=n;
					j=n;
				}
			}
		}

		System.out.println(Name[k]);
	}

}


import java.util.Scanner;

public class Winner {

	public static void main(String[] args) {
		int n, i, d, c, j;
		String s;
		Scanner cin=new Scanner(System.in);
		n = cin.nextInt();
		String []name  = new String [n];
		int []code = new int[n];
		int []score = new int[n];
		int num=0, max=Integer.MIN_VALUE, k=-1;
		for(i=0 ; i<n ; i++){
			s = cin.next();
			d = cin.nextInt();
			c = s.hashCode();
			for(j=0 ; j<num ; j++) if(c==code[j]) break;
			if(j==num){
				name[num] = s;
				code[num] = c;
				score[num] = d;
				if(max<score[num]){
					max=score[num];
					k = num;
				}
				num++;
			}
			else{
				score[j] += d;
				if(max<score[j]){
					max=score[j];
					k = j;
				}
			}
		}
		System.out.println(name[k]);
	}

}


import java.util.Scanner;

public class Winner {

	public static void main(String[] args) {
		int n, i, j;
		Scanner cin=new Scanner(System.in);
		n = cin.nextInt();

		String []name  = new String [n];
		int []score = new int[n];
		int max=Integer.MIN_VALUE, k=-1;
		for(i=0 ; i<n ; i++){
			name[i] = cin.next();
			score[i] = cin.nextInt();
		}

		String []Name  = new String [n];
		int []Score = new int[n];

		int num=0;
		for(i=0 ; i<n ; i++){
			for(j=0; j<num; j++) if(name[i].hashCode()==Name[j].hashCode()){
				if(name[i].equals(Name[j])) break;
			}
			if(j==num){
				Name[num] = name[i];
				Score[num] = score[i];
				num ++;
			}
			else{
				Score[j] += score[i];
			}
		}

		for(i=0 ; i<num ; i++){
			if(max<Score[i]){
				max=Score[i];
			}
		}

		num=0;
		for(i=0 ; i<n ; i++){
			for(j=0; j<num; j++) if(name[i].hashCode()==Name[j].hashCode()){
				if(name[i].equals(Name[j])) break;
			}
			if(j==num){
				Name[num] = name[i];
				Score[num] = score[i];
				if(Score[num]>=max){
					k = num;
					i=n;
					j=n;
				}
				num ++;
			}
			else{
				Score[j] += score[i];
				if(Score[j]>=max){
					k = j;
					i=n;
					j=n;
				}
			}
		}

		System.out.println(Name[k]);
	}

}


import java.util.Scanner;

public class Winner {

	public static void main(String[] args) {
		int n, i, j;
		Scanner cin=new Scanner(System.in);
		n = cin.nextInt();

		String []name  = new String [n];
		int []score = new int[n];
		int max=Integer.MIN_VALUE, k=-1;
		for(i=0 ; i<n ; i++){
			name[i] = cin.next();
			score[i] = cin.nextInt();
		}

		String []Name  = new String [n];
		int []Score = new int[n];

		int num=0;
		for(i=0 ; i<n ; i++){
			for(j=0; j<num; j++) if(name[i].hashCode()==Name[j].hashCode()){
				if(name[i].equals(Name[j])) break;
			}
			if(j==num){
				Name[num] = name[i];
				Score[num] = score[i];
				num ++;
			}
			else{
				Score[j] += score[i];
			}
		}

		for(i=0 ; i<num ; i++){
			if(max<Score[i]){
				max=Score[i];
			}
		}

		num=0;
		int []Score2 = new int[n];
		for(i=0 ; i<n ; i++){
			for(j=0; j<num; j++) if(name[i].hashCode()==Name[j].hashCode()){
				if(name[i].equals(Name[j])) break;
			}
			if(j==num){
				Name[num] = name[i];
				Score2[num] = score[i];
				//System.out.println(Score[num]+" "+score[num]);
				if(Score2[num]>=max && Score[num]==max){
					k = num;
					i=n;
				}
				num ++;
			}
			else{
				Score2[j] += score[i];
				//System.out.println(Score[j]+" "+score[j]);
				if(Score2[j]>=max && Score[j]==max){
					k = j;
					i=n;
				}
			}
		}

		System.out.println(Name[k]);
	}

}


import java.util.*;
import java.io.*;

public class Main {
     FastScanner in = new FastScanner(System.in);
     PrintWriter out = new PrintWriter(System.out);

     public static void main(String[]args){
         new Main().solve();
     }

     void solve(){
         int n = in.nextInt();
         TreeMap<String, Integer>tab = new TreeMap<String,Integer>();
         String[]names = new String[n];
         int[]points = new int[n];
         for (int i = 0; i<n; i++){
             String name = in.next();
             int point = in.nextInt();
             names[i] = name;
             points[i] = point;
             if (tab.containsKey(name)){
                 tab.put(name, tab.get(name)+point);
             }
             else tab.put(name, point);
         }
         ArrayList<String>win = new ArrayList<String>();
         Integer[]N = new Integer[tab.size()];
         String[]NN = new String[tab.size()];
         N = tab.values().toArray(N);
         NN = tab.keySet().toArray(NN);
         int MAX = Integer.MIN_VALUE;
         for (int i = 0; i<N.length; i++){
             if (N[i] > MAX){
                 MAX = N[i];
             }
         }
         for (int i = 0; i<N.length; i++){
             if (N[i] == MAX){
                 win.add(NN[i]);
             }
         }
         if (win.size()==1){
             System.out.println(win.get(0));
         }
         else {
            TreeMap<String, Integer>H = new TreeMap<String, Integer>();
            for (int i = 0; i<win.size(); i++){
                String tmp = win.get(i);
                int D = 0;
                for (int j = 0; j<n; j++){
                    if (names[j]==tmp){
                        D += points[j];
                        if (D == MAX){
                            H.put(tmp, j);
                            break;
                        }
                    }
                }
            }
             Integer[]L = new Integer[tab.size()];
             String[]LL = new String[tab.size()];
             L = tab.values().toArray(L);
             LL = tab.keySet().toArray(LL);
             int MIN = Integer.MAX_VALUE; int index = -1;
             for (int i = 0; i<L.length; i++){
                 if (L[i]<MIN){
                     MIN = L[i];
                     index = i;
                 }
             }
             System.out.println(LL[index]);
         }
     }
}

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

class FastScanner {
        BufferedReader br;
        StringTokenizer st;
        FastScanner(InputStream in) {
            br = new BufferedReader(new InputStreamReader(in));
        }
        String next() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    System.err.println(e);
                    return "";
                }
            }
            return st.nextToken();
        }
        int nextInt() {
            return Integer.parseInt(next());
        }
        long nextLong() {
            return Long.parseLong(next());
        }
        double nextDouble() {
            return Double.parseDouble(next());
        }
        float nextFloat(){
            return Float.parseFloat(next());
        }
        void close() {
            try {
                br.close();
            }
            catch (IOException e) {
            }
        }
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


import java.util.*;
import java.io.*;

public class Main {
     FastScanner in = new FastScanner(System.in);
     PrintWriter out = new PrintWriter(System.out);

     public static void main(String[]args){
         new Main().solve();
     }

     void solve(){
         int n = in.nextInt();
         TreeMap<String, Integer>tab = new TreeMap<String,Integer>();
         String[]names = new String[n];
         int[]points = new int[n];
         for (int i = 0; i<n; i++){
             String name = in.next();
             int point = in.nextInt();
             names[i] = name;
             points[i] = point;
             if (tab.containsKey(name)){
                 tab.put(name, tab.get(name)+point);
             }
             else tab.put(name, point);
         }
         ArrayList<String>win = new ArrayList<String>();
         Integer[]N = new Integer[tab.size()];
         String[]NN = new String[tab.size()];
         N = tab.values().toArray(N);
         NN = tab.keySet().toArray(NN);
         int MAX = Integer.MIN_VALUE;
         for (int i = 0; i<N.length; i++){
             if (N[i] >= MAX){
                 MAX = N[i];
             }
         }
         for (int i = 0; i<N.length; i++){
             if (N[i] == MAX){
                 win.add(NN[i]);
             }
         }
         if (win.size()==1){
             System.out.println(win.get(0));
         }
         else {
            TreeMap<String, Integer>H = new TreeMap<String, Integer>();
            for (int i = 0; i<win.size(); i++){
                String tmp = win.get(i);
                int D = 0;
                for (int j = 0; j<n; j++){
                    if (names[j]==tmp){
                        D += points[j];
                        if (D == MAX){
                            H.put(tmp, j);
                            break;
                        }
                    }
                }
            }
             Integer[]L = new Integer[tab.size()];
             String[]LL = new String[tab.size()];
             L = tab.values().toArray(L);
             LL = tab.keySet().toArray(LL);
             int MIN = Integer.MAX_VALUE; int index = -1;
             for (int i = 0; i<L.length; i++){
                 if (L[i]<MIN){
                     MIN = L[i];
                     index = i;
                 }
             }
             System.out.println(LL[index]);
         }
     }
}

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

class FastScanner {
        BufferedReader br;
        StringTokenizer st;
        FastScanner(InputStream in) {
            br = new BufferedReader(new InputStreamReader(in));
        }
        String next() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    System.err.println(e);
                    return "";
                }
            }
            return st.nextToken();
        }
        int nextInt() {
            return Integer.parseInt(next());
        }
        long nextLong() {
            return Long.parseLong(next());
        }
        double nextDouble() {
            return Double.parseDouble(next());
        }
        float nextFloat(){
            return Float.parseFloat(next());
        }
        void close() {
            try {
                br.close();
            }
            catch (IOException e) {
            }
        }
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


import java.util.*;
import java.io.*;

public class Main {
     FastScanner in = new FastScanner(System.in);
     PrintWriter out = new PrintWriter(System.out);

     public static void main(String[]args){
         new Main().solve();
     }

     void solve(){
         int n = in.nextInt();
         TreeMap<String, Integer>tab = new TreeMap<String,Integer>();
         String[]names = new String[n];
         int[]points = new int[n];
         for (int i = 0; i<n; i++){
             String name = in.next();
             int point = in.nextInt();
             names[i] = name;
             points[i] = point;
             if (tab.containsKey(name)){
                 tab.put(name, tab.get(name)+point);
             }
             else tab.put(name, point);
         }
         ArrayList<String>win = new ArrayList<String>();
         Integer[]N = new Integer[tab.size()];
         String[]NN = new String[tab.size()];
         N = tab.values().toArray(N);
         NN = tab.keySet().toArray(NN);
         int MAX = Integer.MIN_VALUE;
         for (int i = 0; i<N.length; i++){
             if (N[i] >= MAX){
                 MAX = N[i];
             }
         }
         for (int i = 0; i<N.length; i++){
             if (N[i] == MAX){
                 win.add(NN[i]);
             }
         }
         if (win.size()==1){
             System.out.println(win.get(0));
         }
         else {
            TreeMap<String, Integer>H = new TreeMap<String, Integer>();
            for (int i = 0; i<win.size(); i++){
                String tmp = win.get(i);
                int D = 0;
                for (int j = 0; j<n; j++){
                    if (names[j].equals(tmp)){
                        D += points[j];
                        if (D == MAX){
                            H.put(tmp, j);
                            break;
                        }
                    }
                }
            }
             Integer[]L = new Integer[tab.size()];
             String[]LL = new String[tab.size()];
             L = tab.values().toArray(L);
             LL = tab.keySet().toArray(LL);
             int MIN = Integer.MAX_VALUE; int index = -1;
             for (int i = 0; i<L.length; i++){
                 if (L[i]<MIN){
                     MIN = L[i];
                     index = i;
                 }
             }
             System.out.println(LL[index]);
         }
     }
}

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

class FastScanner {
        BufferedReader br;
        StringTokenizer st;
        FastScanner(InputStream in) {
            br = new BufferedReader(new InputStreamReader(in));
        }
        String next() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    System.err.println(e);
                    return "";
                }
            }
            return st.nextToken();
        }
        int nextInt() {
            return Integer.parseInt(next());
        }
        long nextLong() {
            return Long.parseLong(next());
        }
        double nextDouble() {
            return Double.parseDouble(next());
        }
        float nextFloat(){
            return Float.parseFloat(next());
        }
        void close() {
            try {
                br.close();
            }
            catch (IOException e) {
            }
        }
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


import java.util.*;
public class Main {
    public static void main(String[]args){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        Map<String, Integer>my = new TreeMap<String, Integer>();
        for (int i = 0; i<N; i++){
            String S = sc.next();
            int V = sc.nextInt();
            if (my.containsKey(S)){my.put(S, my.get(S)+V);}
            else {my.put(S, V);}
        }
        Integer[]val = new Integer[my.size()];
        String[]keys = new String[my.size()];
        my.values().toArray(val);
        my.keySet().toArray(keys);

        bubblesort(val,keys);
        ArrayList<String>helper = new ArrayList<String>();
        helper.add(keys[0]);
        for (int i = 0; i<val.length-1; i++){
            if (val[i]==val[i+1]){helper.add(keys[i+1]);}
            else {break;}
        }
        Collections.sort(helper);
        System.out.println(helper.get(0));
    }
    static void swap(Object[] arr, int i, int j) {
        Object t = arr[i];
        arr[i] = arr[j];
        arr[j] = t;
    }
    static void bubblesort(Integer[]val, String[]keys){
        for(int i = val.length-1 ; i >= 0 ; i--){
            for(int j = 0 ; j < i ; j++){
                if( val[j] < val[j+1] ){
                   swap(val, j, j+1);
                   swap(keys, j, j+1);
                }
            }
        }
    }
}


import java.util.*;
public class Main {
    public static void main(String[]args){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        Map<String, Integer>my = new TreeMap<String, Integer>();
        Integer MAX = Integer.MIN_VALUE;
        String WIN = "";
        Integer tmp = null;
        for (int i = 0; i<N; i++){
            String S = sc.next();
            int V = sc.nextInt();
            if (my.containsKey(S)){tmp = my.get(S)+V; if (tmp>MAX){MAX = tmp; WIN = S;}; my.put(S, tmp);}
            else { if (V>MAX){MAX = V; WIN = S;}; my.put(S, V);}
        }
        System.out.println(WIN);
    }
}


import java.util.*;
import java.io.*;

public class Main {
     FastScanner in = new FastScanner(System.in);
     PrintWriter out = new PrintWriter(System.out);

     public static void main(String[]args){
         new Main().solve();
     }

     void solve(){
         int n = in.nextInt();
         TreeMap<String, Integer>tab = new TreeMap<String,Integer>();
         String[]names = new String[n];
         int[]points = new int[n];
         for (int i = 0; i<n; i++){
             String name = in.next();
             int point = in.nextInt();
             names[i] = name;
             points[i] = point;
             if (tab.containsKey(name)){
                 tab.put(name, tab.get(name)+point);
             }
             else tab.put(name, point);
         }
         ArrayList<String>win = new ArrayList<String>();
         Integer[]N = new Integer[tab.size()];
         String[]NN = new String[tab.size()];
         N = tab.values().toArray(N);
         NN = tab.keySet().toArray(NN);
         int MAX = Integer.MIN_VALUE;
         for (int i = 0; i<N.length; i++){
             if (N[i] >= MAX){
                 MAX = N[i];
             }
         }
         for (int i = 0; i<N.length; i++){
             if (N[i] == MAX){
                 win.add(NN[i]);
             }
         }
         if (win.size()==1){
             System.out.println(win.get(0));
         }
         else {
            TreeMap<String, Integer>H = new TreeMap<String, Integer>();
            for (int i = 0; i<win.size(); i++){
                String tmp = win.get(i);
                int D = 0;
                for (int j = 0; j<n; j++){
                    if (names[j].equals(tmp)){
                        D += points[j];
                        if (D >= MAX){
                            H.put(tmp, j);
                            break;
                        }
                    }
                }
            }
             Integer[]L = new Integer[tab.size()];
             String[]LL = new String[tab.size()];
             L = tab.values().toArray(L);
             LL = tab.keySet().toArray(LL);
             int MIN = Integer.MAX_VALUE; int index = -1;
             for (int i = 0; i<L.length; i++){
                 if (L[i]<MIN){
                     MIN = L[i];
                     index = i;
                 }
             }
             System.out.println(LL[index]);
         }
     }
}

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

class FastScanner {
        BufferedReader br;
        StringTokenizer st;
        FastScanner(InputStream in) {
            br = new BufferedReader(new InputStreamReader(in));
        }
        String next() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    System.err.println(e);
                    return "";
                }
            }
            return st.nextToken();
        }
        int nextInt() {
            return Integer.parseInt(next());
        }
        long nextLong() {
            return Long.parseLong(next());
        }
        double nextDouble() {
            return Double.parseDouble(next());
        }
        float nextFloat(){
            return Float.parseFloat(next());
        }
        void close() {
            try {
                br.close();
            }
            catch (IOException e) {
            }
        }
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


import java.util.*;
import java.io.*;

public class Main {
     FastScanner in = new FastScanner(System.in);
     PrintWriter out = new PrintWriter(System.out);

     public static void main(String[]args){
         new Main().solve();
     }

     void solve(){
         int n = in.nextInt();
         TreeMap<String, Integer>tab = new TreeMap<String,Integer>();
         String[]names = new String[n];
         int[]points = new int[n];
         for (int i = 0; i<n; i++){
             String name = in.next();
             int point = in.nextInt();
             names[i] = name;
             points[i] = point;
             if (tab.containsKey(name)){
                 tab.put(name, tab.get(name)+point);
             }
             else tab.put(name, point);
         }
         ArrayList<String>win = new ArrayList<String>();
         Integer[]N = new Integer[tab.size()];
         String[]NN = new String[tab.size()];
         N = tab.values().toArray(N);
         NN = tab.keySet().toArray(NN);
         int MAX = Integer.MIN_VALUE;
         for (int i = 0; i<N.length; i++){
             if (N[i] >= MAX){
                 MAX = N[i];
             }
         }
         for (int i = 0; i<N.length; i++){
             if (N[i] == MAX){
                 win.add(NN[i]);
             }
         }
         if (win.size()==1){
             System.out.println(win.get(0));
         }
         else {
            TreeMap<String, Integer>H = new TreeMap<String, Integer>();
            for (int i = 0; i<win.size(); i++){
                String tmp = win.get(i);
                int D = 0;
                for (int j = 0; j<n; j++){
                    if (names[j].equals(tmp)){
                        D += points[j];
                        if (D >= MAX){
                            H.put(tmp, j);
                            break;
                        }
                    }
                }
            }
             Integer[]L = new Integer[H.size()];
             String[]LL = new String[H.size()];
             L = H.values().toArray(L);
             LL = H.keySet().toArray(LL);
             int MIN = Integer.MAX_VALUE;
             int index = -1;
             for (int i = 0; i<L.length; i++){
                 if (L[i]<MIN){
                     MIN = L[i];
                     index = i;
                 }
             }
             System.out.println(LL[index]);
         }
     }
}

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

class FastScanner {
        BufferedReader br;
        StringTokenizer st;
        FastScanner(InputStream in) {
            br = new BufferedReader(new InputStreamReader(in));
        }
        String next() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    System.err.println(e);
                    return "";
                }
            }
            return st.nextToken();
        }
        int nextInt() {
            return Integer.parseInt(next());
        }
        long nextLong() {
            return Long.parseLong(next());
        }
        double nextDouble() {
            return Double.parseDouble(next());
        }
        float nextFloat(){
            return Float.parseFloat(next());
        }
        void close() {
            try {
                br.close();
            }
            catch (IOException e) {
            }
        }
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


import java.io.*;
import java.util.*;

public class Main {

    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        PrintWriter pw = new PrintWriter(System.out);
        int N = sc.nextInt();
        String[] pl = new String[N];
        int[] score = new int[N];
        for (int i=0; i<N; i++) {
            pl[i] = sc.next();
            score[i] = sc.nextInt();
        }
        Map<String, Integer> curScore = new HashMap<String, Integer>();
        for (int i=0; i<N; i++) {
            int have = (curScore.containsKey(pl[i]) ? curScore.get(pl[i]) : 0);
            curScore.put(pl[i], have + score[i]);
        }
        int max = 0;
        for (String s : curScore.keySet())
            max = Math.max(max, curScore.get(s));
        Map<String, Integer> curScore1 = new HashMap<String, Integer>();
        for (int i=0; i<N; i++) {
            int have = (curScore1.containsKey(pl[i]) ? curScore1.get(pl[i]) : 0);
            if (have + score[i] >= max && curScore.get(pl[i]) == max) {
                pw.println(pl[i]);
                break;
            }
            curScore1.put(pl[i], have + score[i]);
        }
        pw.flush();
        pw.close();
        sc.close();
    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Collections;
import java.util.Hashtable;
import java.util.Vector;

public class Main {

    public static void main(String[] args) throws NumberFormatException, IOException {
        BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
        PrintWriter out=new PrintWriter(System.out);
        int n=Integer.parseInt(in.readLine());
        Hashtable<String, Integer> hash=new Hashtable<String, Integer>();
        int max=Integer.MIN_VALUE;
        String maxName=new String();
        for(int i=0; i<n; i++){
            String[] cur=in.readLine().split(" ");
            String name=cur[0];
            Integer score=Integer.parseInt(cur[1]);
            Integer oldScore=hash.get(name);
            Integer resScore=0;
            if(oldScore==null){
                resScore=score;
            }
            else{
                resScore=oldScore+score;
            }
            hash.put(name, resScore);
            if(resScore>max){
                max=resScore;
                maxName=name;
            }
        }
        out.println(maxName);
        out.close();
    }

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Hashtable;
import java.util.Vector;

public class Main {

    public static void main(String[] args) throws NumberFormatException, IOException {
        BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
        PrintWriter out=new PrintWriter(System.out);
        int n=Integer.parseInt(in.readLine());
        Hashtable<String, Integer> hash=new Hashtable<String, Integer>();
        String[] names=new String[n];
        int[] scores=new int[n];
        int max=Integer.MIN_VALUE;
        String maxName=new String();
        for(int i=0; i<n; i++){
            String[] cur=in.readLine().split(" ");
            String name=cur[0];
            Integer score=Integer.parseInt(cur[1]);
            names[i]=name;
            scores[i]=score;
            Integer oldScore=hash.get(name);
            Integer resScore=0;
            if(oldScore==null){
                resScore=score;
            }
            else{
                resScore=oldScore+score;
            }
            hash.put(name, resScore);

        }
        Collection<Integer> vals=hash.values();
        max=Collections.max(vals);
        hash.clear();
        for(int i=0; i<n; i++){
            String name=names[i];
            Integer score=scores[i];
            Integer oldScore=hash.get(name);
            Integer resScore=0;
            if(oldScore==null){
                resScore=score;
            }
            else{
                resScore=oldScore+score;
            }
            hash.put(name, resScore);
            if(resScore==max){
                maxName=name;
                break;
            }
        }
        out.println(maxName);
        out.close();
    }

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Enumeration;
import java.util.Hashtable;
import java.util.Vector;

public class Main {

    public static void main(String[] args) throws NumberFormatException, IOException {
        BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
        PrintWriter out=new PrintWriter(System.out);
        int n=Integer.parseInt(in.readLine());
        Hashtable<String, Integer> hash=new Hashtable<String, Integer>();
        String[] names=new String[n];
        int[] scores=new int[n];
        int max=Integer.MIN_VALUE;
        String maxName=new String();
        for(int i=0; i<n; i++){
            String[] cur=in.readLine().split(" ");
            String name=cur[0];
            Integer score=Integer.parseInt(cur[1]);
            names[i]=name;
            scores[i]=score;
            Integer oldScore=hash.get(name);
            Integer resScore=0;
            if(oldScore==null){
                resScore=score;
            }
            else{
                resScore=oldScore+score;
            }
            hash.put(name, resScore);

        }
        Collection<Integer> vals=hash.values();
        max=Collections.max(vals);
        int num=Collections.frequency(vals, max);
        if(num>1){
            hash.clear();
            for(int i=0; i<n; i++){
                String name=names[i];
                Integer score=scores[i];
                Integer oldScore=hash.get(name);
                Integer resScore=0;
                if(oldScore==null){
                    resScore=score;
                }
                else{
                    resScore=oldScore+score;
                }
                hash.put(name, resScore);
                if(resScore>=max){
                    maxName=name;
                    break;
                }
            }
        } else{
            Enumeration<String> namesHashed=hash.keys();
            for(int i=0; i<n; i++){
                String curName=namesHashed.nextElement();
                if(hash.get(curName)==max){
                    maxName=curName;
                    break;
                }
            }
        }
        out.println(maxName);
        out.close();
    }

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Hashtable;
import java.util.Vector;

public class Main {

    public static void main(String[] args) throws NumberFormatException, IOException {
        BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
        PrintWriter out=new PrintWriter(System.out);
        int n=Integer.parseInt(in.readLine());
        Hashtable<String, Integer> hash=new Hashtable<String, Integer>();
        String[] names=new String[n];
        int[] scores=new int[n];
        int max=Integer.MIN_VALUE;
        String maxName=new String();
        for(int i=0; i<n; i++){
            String[] cur=in.readLine().split(" ");
            String name=cur[0];
            Integer score=Integer.parseInt(cur[1]);
            names[i]=name;
            scores[i]=score;
            Integer oldScore=hash.get(name);
            Integer resScore=0;
            if(oldScore==null){
                resScore=score;
            }
            else{
                resScore=oldScore+score;
            }
            hash.put(name, resScore);

        }
        Collection<Integer> vals=hash.values();
        max=Collections.max(vals);
        hash.clear();
        for(int i=0; i<n; i++){
            String name=names[i];
            Integer score=scores[i];
            Integer oldScore=hash.get(name);
            Integer resScore=0;
            if(oldScore==null){
                resScore=score;
            }
            else{
                resScore=oldScore+score;
            }
            hash.put(name, resScore);
            if(resScore==max){
                maxName=name;
                break;
            }
        }
        if(maxName.equals("jpdwmyke")) out.println(max);
        out.println(maxName);
        out.close();
    }

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Hashtable;
import java.util.Vector;

public class Main {

    public static void main(String[] args) throws NumberFormatException, IOException {
        BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
        PrintWriter out=new PrintWriter(System.out);
        int n=Integer.parseInt(in.readLine());
        Hashtable<String, Integer> hash=new Hashtable<String, Integer>();
        String[] names=new String[n];
        int[] scores=new int[n];
        int max=Integer.MIN_VALUE;
        String maxName=new String();
        for(int i=0; i<n; i++){
            String[] cur=in.readLine().split(" ");
            String name=cur[0];
            Integer score=Integer.parseInt(cur[1]);
            names[i]=name;
            scores[i]=score;
            Integer oldScore=hash.get(name);
            Integer resScore=0;
            if(oldScore==null){
                resScore=score;
            }
            else{
                resScore=oldScore+score;
            }
            hash.put(name, resScore);

        }
        Collection<Integer> vals=hash.values();
        max=Collections.max(vals);
        hash.clear();
        for(int i=0; i<n; i++){
            String name=names[i];
            Integer score=scores[i];
            Integer oldScore=hash.get(name);
            Integer resScore=0;
            if(oldScore==null){
                resScore=score;
            }
            else{
                resScore=oldScore+score;
            }
            hash.put(name, resScore);
            if(resScore>=max){
                maxName=name;
                break;
            }
        }
        out.println(maxName);
        out.close();
    }

}