//********************************
//*??????????? **
//*?????? **
//*???2012.10.29**
//********************************

int main() 
{  

    int n, k, a[100001];         //??????n?????k???a??n???
    cin >> n;                    //??????n
    for (int i = 1; i <= n; i++)
    {
        cin >> a[i];             //??n???????
    }
    cin >> k;                    //????????k
    int temp;                    //??????????????
    a[0] = k - 1;                //?????k????a[0]
    for (int j = 1; j <= n; j++)
    {
        if (a[j] == k) 
        { 
            continue; //??????k???????????
        } 
        else while (a[j - 1] == k)
             { 
                 temp = a[j - 1]; a[j - 1] = a[j]; a[j] = temp;
                 j--;
             } //?????k???????k??????????????k???
    }
    int whether = 0; //??whether?????????
    int r = 1; //????r???? 
    do
    {
        if (whether) cout << " "; //????????????????? 
        cout << a[r]; //??????? 
        whether = 1; //???????? 
        r++; //?????? 
    } while (a[r] != k && r <= n); //??????k?? 
        
    return 0;                     
}   
