N = gets.to_i A = gets.split.map(&:to_i).sort A.unshift(-Float::INFINITY) ans = 0 A.each_cons(2) do |a, b| ans += b if a + 1 != b end puts ans