// FR_14_09 - Przeciążenia procesora.cpp : This file contains the 'main' function. Program execution begins and ends there.
//

#include <iostream>

#include <map>
#include <list>
#include <string>
#include <vector>
#include <deque>

using namespace std;

map<int, int, std::greater<int>> mOdczytCounts;
int* lOdczyts;

deque<pair<int, int>> dOdczyts;

inline void appendInt(std::string& out, int value) 
{
    static char buf[11]; // wystarczy dla 32-bit unsigned int (max 10 cyfr) + '\n'
    char* p = buf + sizeof(buf);

    *--p = '\n';

    do {
        *--p = '0' + (value % 10);
        value /= 10;
    } while (value != 0);

    out.append(p, buf + sizeof(buf) - p);
}

void removeOldestSmallerOrEqualThan(deque<pair<int, int>>& col, int value)
{
    while (col.size() && col.front().second <= value)
        col.pop_front();
}

void removeOldest(deque<pair<int, int>>& col, int index)
{
    while (col.size() && col.front().first <= index)
        col.pop_front();
}

int mainDeque()
{
    int nSize;
    //int odczyt;

    std::ios::sync_with_stdio(false);

    string strOut;
    cin >> nSize;

    int index = 0;
    int value;
    int size = nSize;

    while (nSize--)
    {
        std::cin >> value;

        removeOldestSmallerOrEqualThan(dOdczyts, value);

        dOdczyts.push_back({ index++, value });
    }


    while (std::cin >> value)
    {
        appendInt(strOut, dOdczyts.begin()->second);
            
        removeOldestSmallerOrEqualThan(dOdczyts, value);
        removeOldest(dOdczyts, index - size);

        dOdczyts.push_back({ index++, value });
    }
    
    appendInt(strOut, dOdczyts.begin()->second);

    std::cout << strOut;
    return 0;
}

int mainMapa()
{
    int nSize;
    //int odczyt;

    std::ios::sync_with_stdio(false);

    string strOut;
    cin >> nSize;

    //list<int>::iterator listIt;

    lOdczyts = new int[1000000];
    int* pOdczyt = lOdczyts;

    while (--nSize)
    {
        std::cin >> *pOdczyt;

        ++mOdczytCounts[*pOdczyt++];
    }

    strOut.reserve(10000000);
    int* listIt = lOdczyts;
    //char buf[16]; // wystarczy dla int (nawet z minusem i '\0')

    while (std::cin >> *pOdczyt)
    {
        ++mOdczytCounts[*pOdczyt++];

        //strOut += std::to_string(mOdczytCounts.begin()->first);
        //strOut += '\n';

        //int len = std::snprintf(buf, sizeof(buf), "%d", mOdczytCounts.begin()->first);
        appendInt(strOut, mOdczytCounts.begin()->first);
        //strOut += '\n';

        auto it = mOdczytCounts.find(*listIt);
        it->second--;

        ++listIt;

        if (it->second == 0) mOdczytCounts.erase(it);
    }

    std::cout << strOut;
    return 0;
}

int main()
{
    return mainDeque();
}
