#include <bits/stdc++.h>
#include <unordered_map>

#define eps 1e-8
#define PI 3.141592653589793
#define bsize 512

#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<vector<int>>
#define pb push_back
#define bs 1000000007

using namespace std;

int main()
{
    
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
        
    int n;
    cin>>n;

    int arr[(1<<n)+1];
    arr[0]=-1;

    unordered_map<int, int> pos;

    for(int i=1;i<=(1<<n);i++){
        cin>>arr[i];
        pos[arr[i]]=i;
    }

    for(int i=1;i<=n;i++){
        for(int j=1;j<=(1<<(n-i));j++){
            if(i==n)    arr[j]=min(arr[2*j-1],arr[2*j]);
            else        arr[j]=max(arr[2*j-1],arr[2*j]);
        }
    }

    cout<<pos[arr[1]];

    return 0;
}
#include <bits/stdc++.h>
using namespace std;

const long long MOD = 1e9 + 7;
const int INF = 1e9;
const long long inf = 1LL<<60;

//cout << fixed << setprecision(10) <<  << endl;

bool solve(int left, vector<int> &res, int n, vector<int> &p, vector<int> &ip) {
  if ((int)res.size() == n-1) {
    for (int i=0; i<n; i++) {
      if (p.at(i) != i) return false;
      return true;
    }
  }
  if (ip.at(left) <= left) return false;
  for (int j=ip.at(left); j>left; j--) {
    res.push_back(j);
    swap(p.at(j), p.at(j-1));
  }
  for (int j=left; j < ip.at(left); j++) {
    if (p.at(j) != j) return false;
  }
  return solve(ip.at(left), res, n, p, ip);
}
int main() {
  int n;
  cin >> n;
  vector<int> p(n), ip(n);
  for (int i=0; i<n; i++) {
    cin >> p.at(i); p.at(i)--;
    ip.at(p.at(i)) = i;
  }
  vector<int> res;
  if (!solve(0, res, n, p, ip)) cout << -1 << endl;
  else for (auto v : res) cout << v << endl;
}
