#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */

/* Variables and functions */
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, int *);
int main() {
  int n, i, a = 0;
  scanf("%d", &n);
  int x[n];
  for (i = 0; i < n; i++) {
    scanf("%d", &x[i]);
  }
  for (i = 1; i < n; i++) {
    if (x[i] < x[i - 1]) {
      a = i + 1;
      break;
    }
  }
  if (a != 0)
    printf("%d\n", a);
  else
    printf("0\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x10(%rbp)
lea    0xec3(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1040 <scanf@plt>
mov    -0x8(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x18(%rbp)
lea    0xf(,%rax,4),%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x28(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x20(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    11a9 <main+0x89>
mov    -0x28(%rbp),%rsi
movslq -0xc(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rsi
lea    0xe6a(%rip),%rdi
call   1040 <scanf@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1174 <main+0x54>
movl   $0x1,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    11fa <main+0xda>
mov    -0x28(%rbp),%rcx
movslq -0xc(%rbp),%rax
mov    (%rcx,%rax,4),%eax
mov    -0xc(%rbp),%edx
sub    $0x1,%edx
movslq %edx,%rdx
cmp    (%rcx,%rdx,4),%eax
jge    11e7 <main+0xc7>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    11fa <main+0xda>
jmp    11ec <main+0xcc>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    11b0 <main+0x90>
cmpl   $0x0,-0x10(%rbp)
je     121a <main+0xfa>
mov    -0x10(%rbp),%esi
lea    0xdf5(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1228 <main+0x108>
lea    0xde6(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
lea    0xebb(%rip),%rdi
lea    -0x2c(%rbp),%rsi
call   1050 <scanf@plt>
mov    %rsp,%r15
mov    -0x2c(%rbp),%eax
mov    %rsp,%r12
lea    0xf(,%rax,4),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r12
mov    %r12,%rsp
cmpl   $0x0,-0x2c(%rbp)
jle    11c3 <main+0x93>
xor    %r13d,%r13d
lea    0xe87(%rip),%r14
mov    %r12,%rbx
nopl   0x0(%rax)
mov    %r14,%rdi
mov    %rbx,%rsi
call   1050 <scanf@plt>
add    $0x1,%r13
movslq -0x2c(%rbp),%rax
add    $0x4,%rbx
cmp    %rax,%r13
jl     1180 <main+0x50>
mov    %eax,%eax
cmp    $0x2,%eax
jl     11c3 <main+0x93>
mov    (%r12),%ecx
mov    $0x1,%esi
nopl   0x0(%rax)
mov    %ecx,%edx
mov    (%r12,%rsi,4),%ecx
cmp    %edx,%ecx
jl     11e3 <main+0xb3>
add    $0x1,%rsi
cmp    %rsi,%rax
jne    11b0 <main+0x80>
lea    0xe3d(%rip),%rdi
call   1030 <puts@plt>
mov    %r15,%rsp
xor    %eax,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
add    $0x1,%esi
lea    0xe16(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    11cf <main+0x9f>

LLVM IR (-O0):
@.str = [3 x i8] c"%d\00"
@.str.1 = [4 x i8] c"%d\0A\00"
@.str.2 = [3 x i8] c"0\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i64
store i32 0, i32* %1
store i32 0, i32* %4
%7 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %2)
%8 = load i32, i32* %2
%9 = zext i32 %8 to i64
%10 = call i8* @llvm.stacksave()
store i8* %10, i8** %5
%11 = alloca i32, i64 %9
store i64 %9, i64* %6
store i32 0, i32* %3
br label %12
12: ; preds = %21, %0
%13 = load i32, i32* %3
%14 = load i32, i32* %2
%15 = icmp slt i32 %13, %14
br i1 %15, label %16, label %24
16: ; preds = %12
%17 = load i32, i32* %3
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i32, i32* %11, i64 %18
%20 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %19)
br label %21
21: ; preds = %16
%22 = load i32, i32* %3
%23 = add nsw i32 %22, 1
store i32 %23, i32* %3
br label %12
24: ; preds = %12
store i32 1, i32* %3
br label %25
25: ; preds = %44, %24
%26 = load i32, i32* %3
%27 = load i32, i32* %2
%28 = icmp slt i32 %26, %27
br i1 %28, label %29, label %47
29: ; preds = %25
%30 = load i32, i32* %3
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i32, i32* %11, i64 %31
%33 = load i32, i32* %32
%34 = load i32, i32* %3
%35 = sub nsw i32 %34, 1
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds i32, i32* %11, i64 %36
%38 = load i32, i32* %37
%39 = icmp slt i32 %33, %38
br i1 %39, label %40, label %43
40: ; preds = %29
%41 = load i32, i32* %3
%42 = add nsw i32 %41, 1
store i32 %42, i32* %4
br label %47
43: ; preds = %29
br label %44
44: ; preds = %43
%45 = load i32, i32* %3
%46 = add nsw i32 %45, 1
store i32 %46, i32* %3
br label %25
47: ; preds = %40, %25
%48 = load i32, i32* %4
%49 = icmp ne i32 %48, 0
br i1 %49, label %50, label %53
50: ; preds = %47
%51 = load i32, i32* %4
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %51)
br label %55
53: ; preds = %47
%54 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
br label %55
55: ; preds = %53, %50
store i32 0, i32* %1
%56 = load i8*, i8** %5
%57 = load i32, i32* %1
ret i32 %57
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
@.str.1 = [4 x i8] c"%d\0A\00"
@str = [2 x i8] c"0\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %1)
%4 = load i32, i32* %1
%5 = zext i32 %4 to i64
%6 = call i8* @llvm.stacksave()
%7 = alloca i32, i64 %5
%8 = load i32, i32* %1
%9 = icmp sgt i32 %8, 0
br i1 %9, label %15, label %36
10: ; preds = %15
%11 = icmp sgt i32 %20, 1
br i1 %11, label %12, label %36
12: ; preds = %10
%13 = zext i32 %20 to i64
%14 = load i32, i32* %7
br label %23
15: ; preds = %0, %15
%16 = phi i64 [ %19, %15 ], [ 0, %0 ]
%17 = getelementptr inbounds i32, i32* %7, i64 %16
%18 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %17)
%19 = add nuw nsw i64 %16, 1
%20 = load i32, i32* %1
%21 = sext i32 %20 to i64
%22 = icmp slt i64 %19, %21
br i1 %22, label %15, label %10
23: ; preds = %12, %29
%24 = phi i32 [ %14, %12 ], [ %27, %29 ]
%25 = phi i64 [ 1, %12 ], [ %30, %29 ]
%26 = getelementptr inbounds i32, i32* %7, i64 %25
%27 = load i32, i32* %26
%28 = icmp slt i32 %27, %24
br i1 %28, label %32, label %29
29: ; preds = %23
%30 = add nuw nsw i64 %25, 1
%31 = icmp eq i64 %30, %13
br i1 %31, label %36, label %23
32: ; preds = %23
%33 = trunc i64 %25 to i32
%34 = add nuw nsw i32 %33, 1
%35 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %34)
br label %38
36: ; preds = %29, %0, %10
%37 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @str, i64 0, i64 0))
br label %38
38: ; preds = %36, %32
ret i32 0
}