#pragma region
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#include <set>
#include <list>
#include <iomanip>
#include <cstdint>
#include <bitset>
#include <fstream>
#include <cassert>
#include <numeric>
//#include <atcoder/all>

using namespace std;
//using namespace atcoder;
//using mint = modint;
typedef long long ll;
//#define rep(i, s, e) for (int(i) = (s); (i) < (e); ++(i))
#define rep(i, e) for (int(i) = 0; (i) < (e); ++(i))
#define rrep(i, s) for (int(i) = (s) - 1; (i) >= 0; --(i))
#define all(x) x.begin(),x.end()

#pragma region UnionFind
struct UnionFind
{
	vector<int> par;

	UnionFind(int n) : par(n, -1) {}
	void init(int n) { par.assign(n, -1); }

	int root(int x)
	{
		if (par[x] < 0) return x;
		else return par[x] = root(par[x]);
	}

	bool issame(int x, int y)
	{
		return root(x) == root(y);
	}

	bool merge(int x, int y)
	{
		x = root(x); y = root(y);
		if (x == y) return false;
		if (par[x] > par[y]) swap(x, y);
		par[x] += par[y];
		par[y] = x;
		return true;
	}

	int size(int x)
	{
		return -par[root(x)];
	}
};
#pragma endregion
#pragma region GCD
int gcd(int a, int b)
{
	if (a%b == 0)return b;
	return gcd(b, a%b);
}
#pragma endregion
#pragma region chmin
template<class T> inline bool chmin(T& a, T b)
{
	if (a > b)
	{
		a = b;
		return true;
	}
	return false;
}
#pragma endregion
#pragma region chmax
template<class T> inline bool chmax(T& a, T b)
{
	if (a < b)
	{
		a = b;
		return true;
	}
	return false;
}
#pragma endregion
#pragma region 一次元座圧
template <typename T>
vector<T> compress(vector<T> &X)
{
	vector<T> vals = X;
	sort(all(vals));
	vals.erase(unique(all(vals)), vals.end());
	rep(i, (int)X.size())X[i] = lower_bound(all(vals), X[i]) - vals.begin();
	return vals;
}

#pragma endregion
#pragma endregion


int main()
{
	int n; cin >> n;
	map<int, bool> mp;
	int now = 0;
	rep(i, n)
	{
		int q; cin >> q;
		mp[q] = true;
		while (mp[now])++now;
		cout << now << endl;
	}
}
// For the purpose of C++ competitive programming only.
#include "bits/stdc++.h"
using namespace std;

#define FOR(a, c) for (int(a) = 0; (a) < (c); (a)++)
#define FORL(a, b, c) for (int(a) = (b); (a) < (c); (a)++)
#define FORR(a, b, c) for (int(a) = (b); (a) > (c); (a)--)
#define INF 1000000000000000003
#define MOD 1000000007
#define F first
#define S second
#define pb push_back
#define pob pop_back
#define mp make_pair
#define endl '\n'

typedef long long int ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int N, f = 0, s = 0, t;
    string fn, sn, tn;
    cin >> N;
    FOR(i, N)
    {
        cin >> tn >> t;
        if (t > f)
        {
            s = f;
            f = t;
            sn = fn;
            fn = tn;
        }
        else
        {
            if (t > s)
            {
                s = t;
                sn = tn;
            }
        }
    }
    cout << sn << endl;
    return 0;
}