N = gets.to_i P = gets.split.map(&:to_i) idx = P.index(N) + 1 if N == 1 puts 0 else puts [0, (1..N).sum - 2 * idx].max end