program kode_festival
  implicit none
  integer :: n , a(262144), b(131072), m, i, k
  a = 0
  b = 0
  read(*,*) n
  m = 2**n
  do i = 1, m
    read(*,*) a(i)
  end do
  do k = 1, n
    m = m/2
    do i = 1, m
      if (a(2*i-1).eq.a(2*i)) then
        b(i) = a(2*i-1)
      else
        b(i) = max(a(2*i-1),a(2*i))-min(a(2*i-1),a(2*i))
      end if
    end do
    a(1:m) = b(1:m)
  end do
  write(*,'(i0)') a(1)
  stop
end program kode_festival