let n = stdin.ReadLine() |> int
let a1 =
    stdin.ReadLine()
    |> Seq.toList
    |> List.rev
    |> List.map (int >> fun x -> x-48)
let a2 =
    [0..(n-2)]
    |> List.map (fun x -> (abs (a1.[x+1] - a1.[x])))
if n=2 then stdout.WriteLine (a2.[0])
else
    let a3 =
        [0..(n-3)]
        |> List.map (fun x -> (abs (a2.[x+1] - a2.[x])))
    if n=3 then stdout.WriteLine (a3.[0])
    else
        let rec f i sum x =
            if i=n-2 then sum
            else f (i+1) (sum+(a3.[i])*x) (x*2)
        let x3 = f 0 0 1
        let g v =
            if n%2=1 then ((v >>> (n-3)) ^^^ v)%2 ^^^ ((n-3)/2)%2
            else if n=4 then ((v >>> 1) ^^^ v)%2 ^^^ ((n-3)/2)%2
            else
                let va = (v >>> (n-4)) ^^^ v
                ((va >>> 1) ^^^ va)%2 ^^^ ((n-3)/2)%2
        g x3 |> stdout.WriteLine