#include <bits/stdc++.h>
 
#define rep(i,n) for(ll i=0;i<n;++i)
#define rrep(i, n) for(ll i=n-1;i>=0;--i)
#define rep1(i, n) for(ll i=1; i<=n; ++i)
#define repitr(itr,mp) for(auto itr=mp.begin();itr!=mp.end();itr++)
#define ALL(a) (a).begin(),(a).end()

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

using namespace std;
using ll  = long long;
using ull = unsigned long long;
using pll = pair<ll, ll>;

const ll MOD  = 1e9 + 7;
const ll LINF = 1LL << 60;
const int INF = 1e9 + 7;
const double PI = 3.1415926535897932384626433;

int main(){
    ll n;
    cin >> n;

    rep1(a, 39)rep1(b, 27){
        ull pa, pb;
        pa = pb = 1;

        rep(i, a)pa *= 3;
        rep(i, b)pb *= 5;

        if(pa + pb == n){
            cout << a << " " << b << endl; 
            return 0;
        }
    }

    cout << -1 << endl;
}
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

#define REP(i, n) for(int (i) = 0; (i) < (n); ++(i))
#define REPR(i, n) for(int (i) = (n); (i) >= 0; --(i))
#define FOR(i, n, m) for(int (i) = (n); (i) < (m); ++(i))

constexpr int INF = 1e9;
constexpr ll INFL = 1LL<<61;
constexpr ll mod = 1e9+7;


int main(){
  int N;
  cin >> N;
  vector<int> p(N);
  priority_queue<int, vector<int>, greater<int>> pq;
  REP(i, N){
    cin >> p[i];
  }
  int maxi = 200000;
  REP(i, maxi+1){
    pq.push(i);
  }
  set<int> st;
  REP(i, N){
    st.insert(p[i]);
    while(st.find(pq.top()) != st.end()){
      pq.pop();
    }
    cout << pq.top() << endl;
  }
  return 0; 
}
