N = gets.to_i A = gets.split.map(&:to_i) ans = 0 30.times do |i| base = 2 ** i last = 0 A.each.with_index(1) do |a, idx| if a[i] == 1 last = idx end ans += base * last end end puts ans