Ivan recently bought a detective book. The book is so interesting that each page of this book introduces some sort of a mystery, which will be explained later. The $i$-th page contains some mystery that will be explained on page $a_i$ ($a_i \ge i$).

Ivan wants to read the whole book. Each day, he reads the first page he didn't read earlier, and continues to read the following pages one by one, until all the mysteries he read about are explained and clear to him (Ivan stops if there does not exist any page $i$ such that Ivan already has read it, but hasn't read page $a_i$). After that, he closes the book and continues to read it on the following day from the next page.

How many days will it take to read the whole book?


-----Input-----

The first line contains single integer $n$ ($1 \le n \le 10^4$) — the number of pages in the book.

The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($i \le a_i \le n$), where $a_i$ is the number of page which contains the explanation of the mystery on page $i$.


-----Output-----

Print one integer — the number of days it will take to read the whole book.


-----Example-----
Input
9
1 3 3 6 7 6 8 8 9

Output
4



-----Note-----

Explanation of the example test:

During the first day Ivan will read only the first page. During the second day Ivan will read pages number $2$ and $3$. During the third day — pages $4$-$8$. During the fourth (and the last) day Ivan will read remaining page number $9$.

Difficulty: interview

Starter code:

Solutions:
n = int(input())
a = list(map(int, input().split()))
maxi = 0
ans = 0
for i in range(n):
    a[i] -= 1
    maxi = max(maxi, a[i])
    if maxi == i:
        ans += 1
print(ans)


n = int(input())
ai = list(map(int,input().split()))
num = 0
ans = 0
for i in range(n):
    num = max(num,ai[i] - 1)
    if num == i:
        ans += 1
print(ans)


import math


a = int(input())
s = [int(i) for i in input().split()]
ma = 0
i = 0
k = 0
while i < a:
    ma = max(ma, s[i])
    while ma > i + 1:
        i += 1
        ma = max(ma, s[i])
    i += 1
    k += 1
print(k)


input()
a = list(map(int, input().split(' ')))
days = 0
resolves = set()
for i, b in enumerate(a):
    if not resolves:
        days += 1
    resolves.add(b)
    if i + 1 in resolves:
        resolves.remove(i + 1)
print(days)


n=int(input())
l=list(map(int,input().split()))
ans=0
i=0
mx=0
while(i<n):
    mx=max(mx,l[i])
    if(i==mx-1):
             ans+=1
    i+=1
print(ans)

ii = lambda: int(input())
mi = lambda: map(int, input().split())
li = lambda: list(mi())

n = ii()
a = li()
i = c = 0
while i < n:
    j = a[i] - 1
    while i < j:
        i += 1
        j = max(j, a[i] - 1)
    c += 1
    i += 1
print(c)

n = int(input())

A = input().split()

current_max = 1
days = 0

for i in range(1,n+1):

    current_max=max(current_max,int(A[i-1]))
    if i == current_max:
        ##print(i)
        days += 1

print(days)


N = int(input())
A = [int(a)-1 for a in input().split()]
ma = 0
ans = 0
for i in range(N):
    ma = max(ma, A[i])
    if ma <= i:
        ans += 1
        
print(ans)


n = int(input())
a = [int(x) for x in input().split()]

to = 0
cnt = 1
for i in range(n):
    if i > to:
        cnt += 1
    to = max(to, a[i]-1)
    
print(cnt)


n=int(input())
arr=list(map(int,input().split()))
maxval=arr[0]
ans=0
for i in range(n):
	maxval=max(arr[i],maxval)
	if(maxval==i+1):
		ans+=1
		maxval=0
print(ans)



num = input()
maxi = 0
X = list(map(int,input().split()))
ans = 0
for i in range(int(num)):
    maxi = max(X[i],maxi)
    if i+1==maxi:
        ans +=1
print(ans)


def solve(n, a):
    max_p = 0
    ans = 0

    for p, ai in enumerate(a):
        if ai > max_p:
            max_p = ai
        if p == max_p:
            ans += 1
    return ans




def __starting_point():
    n = int(input())
    a = [int(p) - 1 for p in input().split()]
    print(solve(n, a))

__starting_point()

import sys


def input():
    return sys.stdin.readline().strip()


def print(*x, sep=' ', end='\n'):
    return sys.stdout.write(sep.join(map(str, x)) + end)


def read():
    return sys.stdin.read()


def get():
    return int(input()), [int(i) for i in input().split()]


def out(*arg):
    if type(arg[0]) == list:
        for i in arg[0]:
            print(i)
    else:
        print(arg)


def main():
    n, ls = get()
    stack = -1
    ans = 0
    for i in range(n):
        stack = max(ls[i], i + 1, stack)
        if stack == i + 1:
            ans += 1
    print(ans)


def __starting_point():
    main()

__starting_point()

#      
import collections, atexit, math, sys, bisect 

sys.setrecursionlimit(1000000)

isdebug = False
try :
    #raise ModuleNotFoundError
    import pylint
    import numpy
    def dprint(*args, **kwargs):
        #print(*args, **kwargs, file=sys.stderr)
        # in python 3.4 **kwargs is invalid???
        print(*args,  file=sys.stderr)
    dprint('debug mode')
    isdebug = True
except Exception:
    def dprint(*args, **kwargs):
        pass


def red_inout():
    inId = 0
    outId = 0
    if not isdebug:
        inId = 0
        outId = 0
    if inId>0:
        dprint('use input', inId)
        try:
            f = open('input'+ str(inId) + '.txt', 'r')
            sys.stdin = f #标准输出重定向至文件
        except Exception:
            dprint('invalid input file')
    if outId>0:
        dprint('use output', outId)
        try:
            f = open('stdout'+ str(outId) + '.txt', 'w')
            sys.stdout = f #标准输出重定向至文件
        except Exception:
            dprint('invalid output file')
            
        atexit.register(lambda :sys.stdout.close())     #idle 中不会执行 atexit

if isdebug and len(sys.argv) == 1:
    red_inout()

def getIntList():
    return list(map(int, input().split()))            

def solve(): 
    pass
    
T_ = 1    
#T_, = getIntList()

for iii_ in range(T_):
    #solve()
    N,  = getIntList()
    #print(N)
    za = getIntList()
    now = 0
    r = 0
    for i in range(N):
        now = max(now,za[i]-1)
        if now ==i:
            r+=1
    print(r)


n = int(input())
a = list(map(int, input().split()))
unresolved = []
days = 0
for i in range(n):
    unresolved.append(a[i])
    if max(unresolved) > i+1:
        continue
    else:
        days +=1
        continue

print(days)

rs = lambda : int(input())
ri = lambda : list(map(int, input().split()))
rli = lambda : list(map(int, input().split()))

n = int(input())
a = rli()

mx = 0
ans = 0
for i in range(n):
    mx = max(mx, a[i]-1)
    if mx == i:
        ans += 1

print(ans)


n=int(input())
a=list(map(int, input().split()))
s=set()
ans=0
for i in range(len(a)):
    s.add(a[i]-1)
    if i in s:
        s.remove(i)
    if len(s)==0:
        ans+=1
print(ans)
    


# stdin=open('input.txt')

# def input():
# 	return stdin.readline()[:-1]

# a, b = map(int, input().split())

# l = list(map(int, input().split()))


# CODE BEGINS HERE.................

n = int(input())
a = list(map(int, input().split()))


ans = 1
max_ = 0
for i in range(n - 1):
	if a[i] > max_:
		max_ = a[i]
	if max_ <= i + 1:
		ans += 1


print(ans)
#CODE ENDS HERE....................




import sys

N=int(input())
a=[0]
a[1:]=list(map(int,sys.stdin.readline().rstrip().split()))
ans=0
mys=0
for i in range(1,N+1):
    mys=max(mys,a[i])
    if mys<=i:
        ans+=1
print(ans)


n = int(input().strip())
arr = list(map(lambda x: int(x) - 1, input().strip().split()))

maximum = 0
answer = 0
for start, end in enumerate(arr):
    maximum = max(maximum, end)
    if maximum == start:
        answer += 1

print(answer)

n = int(input())
l = list(map(int, input().split()))
k = 0
p = -1
for i in range(n):
	p = max(p, l[i])
	if p <= i + 1:
		k += 1
print(k) 


n = int(input())
A = list(map(int, input().split()))
Ka = 0
Cnt = 0
for i in range(n):
    Ka = max(Ka, A[i])
    if Ka <= i + 1:
        Cnt += 1
print(Cnt) 

from collections import defaultdict as dd
import math
def nn():
	return int(input())

def li():
	return list(input())

def mi():
	return list(map(int, input().split()))

def lm():
	return list(map(int, input().split()))



n=nn()

l=lm()

maxsofar=0
days=1

for i, num in enumerate(l):
	maxsofar=max(maxsofar, num)
	#print(maxsofar)
	if maxsofar==i+1 and i<len(l)-1:
		days+=1 

print(days)