Buggy python submission (verdict: Runtime Error):
n=int(input())
l=list(map(int,input().split()))
ans=[[]for i in range(max(l)+1)]
for i in range(n):
    ans[l[i]].append(i+1)

    
c=1
tem=[]
ch=0
while 1:
    if len(ans[c])==0:
        break
    else:
        flag=0
        for i in ans[c]:
            if i>ch:
                tem.append(i)
                ch=i
                flag=1
                break
        if not flag:
            break
        else:
            c+=1
                
                
if len(tem)==0:
    print(-1)
else:
    print(n-len(tem))
                
            

Fixed submission:
n=int(input())
l=list(map(int,input().split()))
ans=[[]for i in range(n+1)]
for i in range(n):
    ans[l[i]].append(i+1)

    
c=1
tem=[]
ch=0
while 1:
    if c>n:
        break
    else:
        
        if len(ans[c])==0:
            break
        else:
            flag=0
            for i in ans[c]:
                if i>ch:
                    tem.append(i)
                    ch=i
                    flag=1
                    break
            if not flag:
                break
            else:
                c+=1
                    
                
if len(tem)==0:
    print(-1)
else:
    print(n-len(tem))

Buggy python submission (verdict: Runtime Error):
n=int(input())
l=list(map(int,input().split()))
ans=[[]for i in range(n+1)]
for i in range(n):
    ans[l[i]].append(i+1)

    
c=1
tem=[]
ch=0
while 1:
    if len(ans[c])==0:
        break
    else:
        flag=0
        for i in ans[c]:
            if i>ch:
                tem.append(i)
                ch=i
                flag=1
                break
        if not flag:
            break
        else:
            c+=1
                
                
if len(tem)==0:
    print(-1)
else:
    print(n-len(tem))
                
            

Fixed submission:
n=int(input())
l=list(map(int,input().split()))
ans=[[]for i in range(n+1)]
for i in range(n):
    ans[l[i]].append(i+1)

    
c=1
tem=[]
ch=0
while 1:
    if c>n:
        break
    else:
        
        if len(ans[c])==0:
            break
        else:
            flag=0
            for i in ans[c]:
                if i>ch:
                    tem.append(i)
                    ch=i
                    flag=1
                    break
            if not flag:
                break
            else:
                c+=1
                    
                
if len(tem)==0:
    print(-1)
else:
    print(n-len(tem))

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
l=list(map(int,input().split()))
c=0
pos=0
temp=[]
flag=1
if l.count(1)==0:
    print(-1)
else:
        
    for i in range(1,max(l)+1):
        if i==1:
            
            x=l.index(i)
            temp.append(x)
        else:
            try:
                x=l[temp[-1]::].index(i)+temp[-1]
                temp.append(x)
            except:
    
                break
    
    print(n-len(temp))
            

Fixed submission:
n=int(input())
l=list(map(int,input().split()))
ans=[[]for i in range(n+1)]
for i in range(n):
    ans[l[i]].append(i+1)

    
c=1
tem=[]
ch=0
while 1:
    if c>n:
        break
    else:
        
        if len(ans[c])==0:
            break
        else:
            flag=0
            for i in ans[c]:
                if i>ch:
                    tem.append(i)
                    ch=i
                    flag=1
                    break
            if not flag:
                break
            else:
                c+=1
                    
                
if len(tem)==0:
    print(-1)
else:
    print(n-len(tem))