n = gets.chomp.to_i s = gets.split.map(&:to_i) count = 0 for i in 0..(n-1) if s[i] != (i+1) j = s.index(i+1) s[i], s[j] = s[j], s[i] count += 1 end end puts(1-(count%2)*2)