void main()
{
    long n = rdElem;
    long k = 1L << n;
    long[] a = k.rdCol;

    auto st = SegTree!((x, y) => x == y ? x : abs(x-y), long, 0)(k);
    foreach (i, x; a)
    {
        st.update(i, x);
    }

    st.tree[1].writeln;
}

struct SegTree(alias pred, T, T init)
{
    import core.bitop;
    alias F = binaryFun!pred;

    long n;
    T[] tree;

    this(long n)
    {
        this.n = n == 1 ? 1 : 1L << bsr(n-1) + 2;
        tree.length = this.n << 1;
        tree[] = init;
    }

    ref T opIndex(long idx) pure nothrow
    {
        return tree[idx+this.n];
    }

    void update(long idx, T x)
    {
        idx += this.n;
        this.tree[idx] = x;
        while (idx >>= 1)
        {
            tree[idx] = F(tree[(idx<<1)], tree[(idx<<1)+1]);
        }
    }

    T query(long x, long y)
    {
        T l = init, r = init;
        for (x += this.n, y += this.n; x < y; x >>= 1, y >>= 1)
        {
            if (x & 1) l = F(l, tree[x++]);
            if (y & 1) r = F(tree[--y], r);
        }
        return F(l, r);
    }
}

enum long mod = 10L^^9 + 7;
enum long inf = 1L << 60;
enum double eps = 1.0e-9;

T rdElem(T = long)()
if (!is(T == struct))
{
    return readln.chomp.to!T;
}

alias rdStr = rdElem!string;
alias rdDchar = rdElem!(dchar[]);

T rdElem(T)()
if (is(T == struct))
{
    T result;
    string[] input = rdRow!string;
    assert(T.tupleof.length == input.length);
    foreach (i, ref x; result.tupleof)
    {
        x = input[i].to!(typeof(x));
    }
    return result;
}

T[] rdRow(T = long)()
{
    return readln.split.to!(T[]);
}

T[] rdCol(T = long)(long col)
{
    return iota(col).map!(x => rdElem!T).array;
}

T[][] rdMat(T = long)(long col)
{
    return iota(col).map!(x => rdRow!T).array;
}

void rdVals(T...)(ref T data)
{
    string[] input = rdRow!string;
    assert(data.length == input.length);
    foreach (i, ref x; data)
    {
        x = input[i].to!(typeof(x));
    }
}

void wrMat(T = long)(T[][] mat)
{
    foreach (row; mat)
    {
        foreach (j, compo; row)
        {
            compo.write;
            if (j == row.length - 1) writeln;
            else " ".write;
        }
    }
}

import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.mathspecial;
import std.traits;
import std.container;
import std.functional;
import std.typecons;
import std.ascii;
import std.uni;
import core.bitop;