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: EASY
Tags: Implementation

Starter code:

Solutions:
pages = int(input())
mysts = list(map(int, input().split()))
days = 0
read_up_till = 0
for (i, ai) in enumerate(mysts):
	if ai >= read_up_till:
		read_up_till = ai
	if i == read_up_till - 1:
		days += 1
print(days)


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


n = int(input())
a = list(map(int, input().split(' ')))
d = 0
t = []
for i in range(n):
	t.insert(-1, a[i])
	if max(t) == i + 1:
		d += 1
		t = []
print(d)


days = 0
pages = int(input())
mis = list(map(int, input().split()))
d_c = 0
p_c = 1
maxx = mis[0]
for i in range(0, pages):
	maxx = max(mis[i], maxx)
	if maxx == i + 1:
		d_c += 1
print(d_c)


n = int(input())
L = input().split(' ')
L = list(map(int, L))
i = 0
c = 0
p = 0
while i < n:
	if L[i] > p:
		p = L[i]
	if i == p - 1:
		c += 1
	i += 1
print(c)


input()
temp = list(map(int, input().split()))
s = 0
mx = 0
for i in range(len(temp)):
	mx = max(mx, temp[i])
	if mx <= i + 1:
		s += 1
	else:
		continue
print(s)


n = int(input())
x = list(map(int, input().split(' ')))
Max = -1
count = 0
for i in range(n):
	x[i] -= 1
	if Max < i:
		count += 1
	Max = max(Max, x[i])
print(count)


n = int(input())
cnt = 0
m = 0
l = list(map(int, input().split()))
for i in range(n):
	m = max(m, l[i])
	if l[i] == i + 1 and m == l[i]:
		cnt += 1
print(cnt)


n = int(input())
count = 0
max_1 = 1
j = 0
a = list(map(int, input().split()))
while j < n:
	max_1 = max(max_1, a[j])
	while max_1 > j:
		max_1 = max(max_1, a[j])
		j += 1
	count += 1
print(count)


n = int(input())
li = list(map(int, input().split()))
for i in range(n):
	li[i] = li[i] - 1
count = 0
pos = 0
while pos < n:
	count = count + 1
	maxi = pos
	while pos < n and pos <= maxi:
		maxi = max(maxi, li[pos])
		pos = pos + 1
print(count)


n = int(input())
a = list(map(int, input().split()))
count = 0
i = 0
while i < n:
	count += 1
	m = a[i]
	i += 1
	while i < n and i < m:
		if a[i] > m:
			m = a[i]
		i += 1
print(count)


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)


n = int(input())
a = list(map(int, input().split()))
c = 0
k = a[0]
for i in range(len(a)):
	if a[i] == i + 1 and k <= a[i]:
		c += 1
	elif k < a[i]:
		k = a[i]
print(c)


n = int(input())
arr = map(int, input().split())
ans = 0
j = 1
t = 1
for i in arr:
	j = max(j, i)
	if j == t:
		ans += 1
	t += 1
print(ans)


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)


n = int(input())
arr = list(map(int, input().split()))
high = 0
count = 0
for i in range(n):
	j = i + 1
	if high < arr[i]:
		high = arr[i]
	if j >= high:
		count += 1
print(count)


def ri():
	return int(input())

def rl():
	return list(map(int, input().split()))
n = ri()
a = rl()
days = 0
unsolved = set([])
for i in range(n):
	if i + 1 in unsolved:
		unsolved.remove(i + 1)
	if a[i] == i + 1:
		if len(unsolved) == 0:
			days += 1
	else:
		unsolved.add(a[i])
print(days)


n = int(input())
aas = list(map(int, input().split(' ')))
total_pages = len(aas)

def days_to_read(tp, v):
	d = 0
	p = 0
	while p < tp:
		p += pages_to_read_one_day(v, p)
		d += 1
	return d

def pages_to_read_one_day(v, page_day_before):
	j = page_day_before + 1
	while max(v[:j]) > j:
		j += 1
	return j - page_day_before
print(days_to_read(total_pages, aas))


n = int(input())
p = list(map(int, input().split()))
(i, z, t) = (0, 0, 0)
while i < n:
	z = max(z, p[i])
	if z == i + 1:
		t += 1
	i += 1
print(t)


input()
X = list(map(int, input().split()))
(Count, i) = (0, 0)
while i < len(X):
	Max = X[i] - 1
	while i <= Max:
		(Max, i) = (max(Max, X[i] - 1), i + 1)
	Count += 1
print(Count)


n = eval(input())
ans = nd = 0
a = list(map(int, input().split()))
for i in range(n):
	nd = max(nd, a[i])
	if nd - 1 == 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())
(*a,) = map(int, input().split())
(ans, counter) = (0, 0)
for i in range(n):
	counter = max(a[i], counter)
	if counter == i + 1:
		ans += 1
print(ans)


from collections import defaultdict
n = int(input())
a = list(map(int, input().rstrip().split(' ')))
b = defaultdict(set)
for (idx, item) in enumerate(a):
	b[item] |= {idx + 1}
days = 0
secrets_exists = set()
for i in range(1, n + 1):
	secrets_exists.add(i)
	secrets_exists -= b[i]
	if len(secrets_exists) == 0:
		days += 1
print(days)


def mistery_book():
	length = input().split()
	array = list(map(int, input().split()))
	i = 0
	output = 0
	maximum = 1
	while i != len(array):
		if array[i] == i + 1:
			if i + 1 == maximum:
				maximum += 1
				output += 1
			i += 1
		elif array[i] > maximum:
			maximum = array[i]
			i += 1
		elif i != maximum - 1:
			i += 1
	return output
test = mistery_book()
print(test)


from math import *
n = int(input())
a = list(map(int, input().split(' ')))
for i in range(n):
	a[i] -= 1
mx = 0
day = 0
i = 0
while i < n:
	day += 1
	mx = max(mx, a[i])
	j = i
	while j < n and j <= mx:
		mx = max(mx, a[j])
		j += 1
	i = j
print(day)


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


n = int(input())
x = [int(n) for n in input().split()]
i = 0
c = 0
li = []
while i != n:
	li.append(x[i])
	if i + 1 == x[i] and max(li) <= x[i]:
		c += 1
	i += 1
print(c)


n = int(input())
v = [int(i) - 1 for i in input().split()]
ind = 0
sol = 0
while ind < n:
	sol += 1
	mx = ind
	while ind < n and ind <= mx:
		mx = max(mx, v[ind])
		ind += 1
print(sol)


n = int(input())
a = list(map(int, input().split()))
cur_pos = 0
current_revealed = 0
c = 0
while cur_pos < n:
	c += 1
	current_revealed += 1
	while cur_pos < current_revealed:
		current_revealed = max(current_revealed, a[cur_pos])
		cur_pos += 1
print(c)


n = int(input())
l = [int(x) for x in input().split()]
days = 0
maxi = 0
for i in range(n):
	maxi = max(maxi, l[i])
	if i + 1 == l[i] and i + 1 >= maxi:
		days += 1
print(days)


I = lambda : map(int, input().split())
n = int(input())
li = [0] + list(I())
t = 1
ans = 0
while t <= n:
	maxx = t
	for i in range(t, n + 1):
		maxx = max(li[i], maxx)
		if maxx == i:
			t = i + 1
			break
	ans += 1
print(ans)


n = int(input())
a = [int(i) for i in input().split()]
(days, maxi) = (0, 0)
for i in range(n):
	if maxi < a[i]:
		maxi = a[i]
	if a[i] == i + 1:
		if a[i] == maxi:
			days += 1
print(days)


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


import sys
import math
get_string = lambda : sys.stdin.readline().strip()
get_int_list = lambda : list(map(int, sys.stdin.readline().strip().split()))
get_intList_from_str = lambda : list(map(int, list(sys.stdin.readline().strip())))
get_charList_from_str = lambda : list(sys.stdin.readline().strip())
get_char_list = lambda : sys.stdin.readline().strip().split()
get_int = lambda : int(sys.stdin.readline())
pt = lambda x: sys.stdout.write(str(x))
n = int(input())
lst = list(map(int, input().split()))
count = 0
m = 0
for i in range(n):
	m = max(m, lst[i])
	if m == i + 1:
		count += 1
print(count)


from sys import stdin, stdout
from itertools import combinations
from collections import defaultdict
import math

def listIn():
	return list(map(int, stdin.readline().strip().split()))

def stringListIn():
	return [x for x in stdin.readline().split()]

def intIn():
	return int(stdin.readline())

def stringIn():
	return stdin.readline().strip()
n = intIn()
a = listIn()
cnt = 0
s = float('-inf')
st = 1
for i in range(1, n + 1):
	s = max(s, a[i - 1])
	if s == i:
		cnt += 1
print(cnt)


n = int(input())
l = [int(i) for i in input().split()]
cnt = 0
vis = [0] * n
for i in range(n):
	if vis[i] == 0:
		cnt += 1
	curr = l[i]
	j = 0
	while j < curr:
		curr = max(curr, l[j])
		vis[j] = 1
		j += 1
print(cnt)


n = int(input())
A = list(map(int, input().split()))
i = 0
day = 0
MAX = A[0]
while i < n:
	if i == MAX - 1:
		day += 1
		i += 1
		if i < n:
			MAX = A[i]
	else:
		i += 1
		if i < n:
			MAX = max(MAX, A[i])
print(day)


a = [0] * int(input())
for i in map(int, input().split()):
	a[i - 1] += 1
r = c = 0
for x in a:
	c += 1 - x
	r += c == 0
print(r)


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


n = int(input())
a = [int(i) for i in input().split()]
(k, i) = (0, 0)
while i != n:
	k += 1
	i += 1
	z = set()
	z.add(a[i - 1])
	while i != max(z):
		i += 1
		z.add(a[i - 1])
print(k)


n = int(input())
l = list(map(int, input().split()))
ans = 0
ma = 0
for i in range(n):
	if l[i] > ma and i >= ma:
		ans += 1
		ma = l[i]
	elif l[i] > ma and i < ma:
		ma = l[i]
print(ans)


N = int(input())
A = list(map(int, input().split()))
days = 0
flag = 1
i = 1
while True:
	if i > N:
		break
	a_i = A[i - 1]
	I = i
	i = a_i
	if a_i >= I:
		for j in range(I, a_i + 1):
			flag = 1
			if A[j - 1] > a_i:
				i = j - 1
				flag = 0
				break
		if flag:
			days += 1
	if I == N:
		break
	i += 1
print(days)


n = int(input())
mys = list(map(int, input().split()))
(d, largest) = (0, 1)
for i in range(1, n + 1):
	if i == largest and mys[i - 1] == largest:
		d += 1
		largest = i + 1
	else:
		largest = max(largest, mys[i - 1])
print(d)


def main():
	input()
	res = m = 0
	for (i, a) in enumerate(map(int, input().split()), 1):
		if m < a:
			m = a
		res += m == i
	print(res)
main()


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


N = int(input())
days = 0
cmax = 0
for (i, a) in enumerate(map(int, input().split())):
	if i + 1 > cmax:
		days += 1
	cmax = max(cmax, a)
print(days)


def detectiv(lst):
	count = 0
	for i in range(len(lst)):
		if lst[i] == i + 1:
			count += 1
	return count
n = int(input())
a = [int(j) for j in input().split()]
print(detectiv(sorted(a)))


n = int(input())
a = list(map(int, input().split()))
day = 0
page = 0
while page < n:
	day += 1
	page += 1
	end = a[page - 1]
	while page < end:
		page += 1
		end = max(a[page - 1], end)
print(day)


(n, l) = (int(input()), list(map(int, input().split())))
(ans, read, cnt) = (0, 0, 0)
while read < n:
	ans += 1
	tmp = read
	read += 1
	while tmp < read:
		read = max(read, l[tmp])
		tmp += 1
print(ans)


N = int(input())
cnt = 0
m = [*map(int, input().split())]
k = -1
for i in range(N):
	k = max(m[i] - 1, k)
	if k == i:
		cnt += 1
print(cnt)


n = int(input())
a = [int(a) for a in input().split()]
c = 0
ma = a[0]
for i in range(n):
	ma = max(ma, a[i])
	if i + 1 == ma:
		c += 1
print(c)


n = int(input())
lst1 = list(map(int, input().split()))
for i in range(len(lst1)):
	lst1[i] -= 1
count = 1
i = 0
max1 = lst1[0]
count = 0
for i in range(len(lst1) - 1):
	if lst1[i] > max1:
		max1 = lst1[i]
	if max1 < i + 1:
		count += 1
print(count + 1)


n = int(input())
a = list(map(int, input().split()))
res = 0
i = 0
finish = -1
while i < n:
	j = a[i] - 1
	if finish < i:
		res += 1
	i += 1
	finish = max(finish, j)
print(res)


i = int(input())
b = input().split()
max = int(b[0])
count = 0
for j in range(0, i):
	if int(max) < int(b[j]):
		max = int(b[j])
	if int(max) == int(j) + 1:
		count = count + 1
		max = 0
print(count)


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


n = int(input())
a = list(map(int, input().split()))
b = [0] * n
k = 0
cp = 0
r = a[0]
while cp < n:
	k += 1
	r = a[cp]
	while cp < n and cp + 1 <= r:
		r = max(r, a[cp])
		cp += 1
print(k)


n = int(input())
a = list(map(int, input().split()))
i = 0
ans = 0
while i < n:
	now = a[i]
	while i < n and now > i + 1:
		i += 1
		now = max(now, a[i])
	ans += 1
	i += 1
print(ans)


input()
r = k = 0
i = 1
for x in map(int, input().split()):
	k = max(k, x)
	r += k == i
	i += 1
print(r)


_ = int(input())
_1_ = list(map(int, input().split()))
_X_ = 0
_MAX_ = _1_[0]
_i_ = 0
while True:
	_TMP_ = max(_1_[_i_:_MAX_])
	if _TMP_ <= _MAX_:
		i = _MAX_
		_X_ += 1
		_MAX_ += 1
	else:
		_MAX_ = _TMP_
		if _TMP_ == _:
			_X_ += 1
			break
	if _TMP_ == _:
		break
print(_X_)


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


n = int(input())
l = list(map(int, input().strip().split(' ')))
count = 0
skip = 1
f = 0
for i in range(n):
	if f == 1:
		skip = max(skip, l[i])
		if i + 1 == skip:
			f = 0
			count += 1
	elif l[i] != i + 1:
		f = 1
		skip = l[i]
	else:
		f = 0
		count += 1
print(count)


def solve(a):
	res = 0
	nxt = 0
	for (i, j) in enumerate(a):
		if j > nxt:
			nxt = j
		if i + 1 == nxt:
			res += 1
	return res
t = 1
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	res = solve(a)
	print(res)


input()
cnt = 0
ma = 0
for (i, x) in enumerate(list(map(int, input().split()))):
	ma = max(ma, x)
	if i + 1 == x and ma == i + 1:
		cnt += 1
print(cnt)


__author__ = 'NIORLYS'
n = int(input())
a = list(map(int, input().split()))
d = {}
days = 0
exp = 1
for i in range(n):
	exp = max(a[i], exp)
	if i + 1 == exp:
		days += 1
print(days)


n = int(input())
l = list(map(int, input().split()))
l2 = []
s = 0
for i in range(len(l)):
	l2.append(l[i])
	if max(l2) <= i + 1:
		s = s + 1
print(s)


n = int(input())
a = (*map(int, input().split()),)
r = i = 0
while i < n:
	c = a[i] - 1
	while i != c:
		i += 1
		c = max(c, a[i] - 1)
	i += 1
	r += 1
print(r)


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


n = int(input())
A = [*map(int, input().split())]
r = 0
i = 1
m = 1
for a in A:
	m = max(m, a)
	if i == m:
		r += 1
	i += 1
print(r)


import sys
import math
fileoperation = 0
if fileoperation:
	orig_stdout = sys.stdout
	orig_stdin = sys.stdin
	inputfile = open('W:/Competitive Programming/input.txt', 'r')
	outputfile = open('W:/Competitive Programming/output.txt', 'w')
	sys.stdin = inputfile
	sys.stdout = outputfile
mod = 1000000007

def nospace(l):
	ans = ''.join((str(i) for i in l))
	return ans
t = 1
for tt in range(t):
	n = int(input())
	a = list(map(int, sys.stdin.readline().split(' ')))
	pg = 1
	ans = 0
	mm = 0
	for i in range(n):
		mm = max(a[:i + 1])
		if a[i] == i + 1 and mm <= i + 1:
			ans += 1
	print(ans)
if fileoperation:
	sys.stdout = orig_stdout
	sys.stdin = orig_stdin
	inputfile.close()
	outputfile.close()


n = int(input())
s = list(map(int, input().split()))
g = 0
q = 0
for i in range(1, n + 1):
	if s[i - 1] > g:
		g = s[i - 1]
	if i == g:
		q += 1
print(q)


TN = 1

def solution():
	n = int(input())
	a = list(map(int, input().split()))
	lst = []
	k = 0
	ans = 0
	for i in range(n):
		if a[i] not in lst:
			lst.append(a[i])
			k += 1
		if i + 1 in lst:
			lst = lst[:i + 1] + lst[i + 2:]
			k -= 1
		if k == 0:
			ans += 1
	print(ans)
while TN != 0:
	solution()
	TN -= 1


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


import os
import sys
debug = True
if debug and os.path.exists('input.in'):
	input = open('input.in', 'r').readline
else:
	debug = False
	input = sys.stdin.readline

def inp():
	return int(input())

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

def insr():
	s = input()
	return s[:len(s) - 1]

def invr():
	return map(int, input().split())
test_count = 1
if debug:
	test_count = inp()
for t in range(test_count):
	if debug:
		print('Test Case #', t + 1)
	n = inp()
	a = inlt()
	m = 0
	ans = 0
	for i in range(1, n + 1):
		m = max(m, a[i - 1])
		if m <= i:
			ans += 1
	print(ans)


n = int(input())
a = [int(s) for s in input().split()]
i = 0
maxpage = 0
days = 0
for i in range(n):
	maxpage = max(maxpage, a[i])
	if maxpage == i + 1:
		days += 1
		maxpage = 0
print(days)


n = eval(input())
s = input().split(' ')
s = list(map(int, s))
count = 0
max = 0
index = 0
while index < n:
	if max < s[index]:
		max = s[index]
	if max - 1 == index:
		count += 1
	index += 1
print(count)


R = lambda : map(int, input().split())
cnt = 0
n = int(input())
ls = tuple(R())
i = 0
t = 0
while i < n:
	t = max(t, ls[i])
	while i < t - 1 and i < n - 1:
		i += 1
		t = max(t, ls[i])
	i += 1
	cnt += 1
print(cnt)


n = int(input())
l = list(map(int, input().split()))
ans = 0
s = []
for i in range(n):
	if l[i] not in s:
		s.append(l[i])
	if i + 1 in s:
		del s[s.index(i + 1)]
	if len(s) == 0:
		ans += 1
print(ans)


import sys
from collections import defaultdict as dd
from itertools import permutations as pp
from itertools import combinations as cc
from collections import Counter as ccd
from random import randint as rd
from bisect import bisect_left as bl
import heapq
mod = 10 ** 9 + 7

def ri(flag=0):
	if flag == 0:
		return [int(i) for i in sys.stdin.readline().split()]
	else:
		return int(sys.stdin.readline())
n = ri(1)
a = ri()
ans = 0
cur = 0
for i in range(n):
	if cur < i + 1:
		ans += 1
		cur = max(cur, a[i])
	else:
		cur = max(cur, a[i])
print(ans)


n = int(input())
a = [*map(int, input().split())]
k = 0
o = 0
for i in range(n):
	k = max(a[i], k)
	if a[i] == k and k == i + 1:
		o += 1
print(o)


import sys
printn = lambda x: sys.stdout.write(x)
DBG = not True

def ddprint(x):
	if DBG:
		print(x)
n = int(input())
aa = list(map(int, input().split()))
a = [x - 1 for x in aa]
ddprint(a)
day = 0
page = 0
while page < n:
	mx = a[page]
	ddprint('mx {}'.format(mx))
	while page < n:
		mx = max(mx, a[page])
		dobrk = False
		if page >= mx:
			dobrk = True
		page += 1
		if dobrk:
			break
		ddprint('mx {} pg {}'.format(mx, page))
	ddprint('eod mx {} pg {} day {}'.format(mx, page, day))
	day += 1
print(day)


n = int(input())
ma = -1
count = 0
day = 0
a = [int(j) for j in input().split()]
xyz = 0
while xyz < n:
	lim = a[xyz]
	while xyz != lim:
		lim = max(a[xyz], lim)
		xyz += 1
	day += 1
print(day)


R = lambda : map(int, input().split())
n = int(input())
r = m = 0
for (i, a) in enumerate(R(), 1):
	m = max(m, a)
	if m == i:
		r += 1
print(r)


from collections import Counter, defaultdict, deque
import itertools
n = int(input())
a = list(map(int, input().split()))
for i in range(n):
	a[i] -= 1
ans = 0
i = 0
nxt = 0
for i in range(n):
	if i == nxt and a[i] == i:
		ans += 1
		nxt = a[i + 1] if i + 1 < n else 0
	elif a[i] > nxt:
		nxt = a[i]
print(ans)


num = int(input())
arr = [int(x) for x in input().split()]
maxx = 0
count = 0
for i in range(0, num):
	if arr[i] - 1 > maxx:
		maxx = arr[i] - 1
	if i >= maxx:
		count += 1
print(count)


import sys
n = int(sys.stdin.readline().strip())
x = list(map(int, sys.stdin.readline().strip().split()))
for i in range(len(x)):
	x[i] -= 1
d = 0
i = 0
t = x[0]
while True:
	if i == len(x):
		break
	if t > i or x[i] > t:
		t = max(t, x[i])
	else:
		if i < len(x) - 1:
			t = x[i + 1]
		d += 1
	i += 1
print(d)


N = int(input())
a_list = list(map(int, input().split()))
now = 1
next_mis = -1
ans = 0
for (i, a) in enumerate(a_list):
	i += 1
	next_mis = max(next_mis, a)
	if next_mis <= i:
		ans += 1
		next_mis = -1
	else:
		now = next_mis
print(ans)


n = int(input())
l = list(map(int, input().split()))
c = 0
a = 0
for i in range(n):
	if i + 1 > c:
		a += 1
	c = max(c, l[i])
print(a)


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()


n = int(input())
arr = list(map(int, input().split()))
vis = [0] * n
ans = 0
i = 0
while i <= n - 1:
	ans += 1
	val = arr[i]
	while True:
		max1 = 0
		for j in range(i, val):
			max1 = max(max1, arr[j])
		if max1 > val:
			val = max1
		else:
			break
	i = max1
print(ans)


from itertools import accumulate
input()
pages = list(map(int, input().split(' ')))
max_pages = [0] + list(accumulate(pages, max))
days = sum((int(max_pages[i] == i) for i in range(len(pages))))
print(days)


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)


print(sum((int(p == i + 1) for (i, p) in enumerate(__import__('itertools').accumulate(map(int, (input(), input())[1].split(' ')), max)))))


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


n = int(input())
a = [int(i) for i in input().split()]
(k, i, z) = (0, 0, a[0])
while i != n:
	k += 1
	i += 1
	z = a[i - 1] if a[i - 1] > z else z
	while i != z:
		i += 1
		z = a[i - 1] if a[i - 1] > z else z
print(k)


n = int(input())
a = [int(i) for i in input().split()]
i = 0
d = 0
while i < n:
	max1 = a[i]
	while i + 1 <= max1:
		max1 = max(max1, a[i])
		i += 1
	d += 1
print(d)


n = int(input())
arr = [0] + list(map(int, input().split()))
maxi = max(arr)
bookindex = 1
toread = []
counter = 0
while bookindex <= maxi:
	toread.append(arr[bookindex])
	if bookindex == max(toread):
		counter += 1
	bookindex += 1
print(counter)


days = 0
max = 1
st = []
n = int(input())
vhod = input()
chisla = vhod.split(' ')
for i in range(n):
	cur = int(chisla[i])
	if cur > max:
		max = cur
	elif cur == max:
		if i == max - 1:
			days += 1
			max += 1
print(days)


n = int(input())
a = list(map(int, input().split()))
j = 1
c = 0
count = [0] * (n + 1)
for i in range(len(a)):
	if count[i + 1] == 1:
		while j <= a[i]:
			count[j] += 1
			j += 1
	if count[a[i]] == 0:
		c += 1
		while j <= a[i]:
			count[j] += 1
			j += 1
print(c)


n = int(input())
a = [int(i) for i in input().split()]
unsolved_mysteries = list()
days = int(0)
for i in range(n):
	if len(unsolved_mysteries) == 0:
		days += 1
	if a[i] - 1 > i:
		unsolved_mysteries.append(a[i] - 1)
		unsolved_mysteries.sort()
		j = 0
	while len(unsolved_mysteries) > 0 and unsolved_mysteries[j] <= i:
		unsolved_mysteries.pop(j)
print(days)


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


a = int(input())
li = [0 for _ in range(a + 1)]
l = list(map(int, input().split()))
c = 0
s = 0
for i in range(a):
	if li[l[i]] == 0:
		c += 1
		li[l[i]] = 1
	if li[i + 1] == 1:
		c -= 1
	if c == 0:
		s += 1
print(s)


n = int(input())
s = [0] + [int(x) for x in input().split()]
ans = 0
mx = 0
for i in range(1, len(s)):
	mx = max(mx, s[i])
	if i == mx:
		ans += 1
print(ans)


n = int(input())
a = list(map(int, input().split()))
day = 0
pmystery = []
pm = []
for i in range(10005):
	pm.append(0)
for i in range(0, n):
	while 1:
		if i + 1 in pmystery:
			pmystery.remove(i + 1)
		else:
			break
	if i + 1 == a[i] and len(pmystery) == 0:
		day += 1
	elif i + 1 != a[i]:
		pmystery.append(a[i])
		pm[i + 1] = 1
print(day)


n = int(input())
l = list(map(int, input().split()))
mi = 1
count = 0
i = 0
while i < n:
	mi = l[i]
	ind = i
	while i < mi and i < n:
		mi = max(mi, l[i])
		i += 1
	count += 1
	if ind == i:
		i += 1
print(count)


from sys import stdin, stdout
import math
n = int(stdin.readline().strip())
arr = list(map(int, stdin.readline().split()))
count = 0
mx = arr[0]
for i in range(1, n + 1):
	mx = max(arr[i - 1], mx)
	if mx == i:
		count += 1
print(count)


n = int(input())
misteries = [int(i) for i in input().split(' ')]
reading = 0
days = 0
nextMisterie = 0
for a in misteries:
	if a > nextMisterie:
		nextMisterie = a
	if reading == nextMisterie - 1:
		days += 1
	reading += 1
print(days)


n = int(input())
a = list(map(int, input().split()))
status = True
answer = 0
r = 0
for i in range(1, n + 1):
	if r == i:
		status = True
	if a[i - 1] <= i:
		if status:
			answer += 1
		else:
			continue
	else:
		if r < a[i - 1]:
			r = a[i - 1]
		status = False
print(answer)


n = int(input())
arr = input().split(' ')
count = 0
d = 0
for i in range(len(arr)):
	arr[i] = int(arr[i])
	if arr[i] > count:
		count = arr[i]
	if count == i + 1:
		d += 1
print(d)


import sys
sys.setrecursionlimit(10 ** 9)
input = sys.stdin.readline
N = int(input())
L = list(map(int, input().split()))
l = 0
ap = []
ans = 0
for (i, l) in enumerate(L):
	ap.append(l)
	if i + 1 >= max(ap):
		ans += 1
print(ans)


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()))
a.insert(0, 0)
count = 0
a.sort()
for i in range(1, len(a)):
	if i == a[i]:
		count += 1
print(count)


n = int(input())
mas = input().split(' ')
days = 0
secret = 0
for i in range(n):
	secret = max(secret, int(mas[i]))
	if secret <= i + 1:
		days += 1
print(days)


def fastio():
	import sys
	from io import StringIO
	from atexit import register
	global input
	sys.stdin = StringIO(sys.stdin.read())
	input = lambda : sys.stdin.readline().rstrip('\r\n')
	sys.stdout = StringIO()
	register(lambda : sys.__stdout__.write(sys.stdout.getvalue()))
fastio()
MOD = 10 ** 9 + 7
I = lambda : list(map(int, input().split()))
(n,) = I()
a = [0] + I()
ans = 0
k = 0
for i in range(1, n + 1):
	if i <= k:
		k = max(k, a[i])
		continue
	k = max(k, a[i])
	ans += 1
print(ans)


N = int(input())
A = list(map(int, input().split()))
ans = 0
e = set()
for (i, a) in enumerate(A, 1):
	if i < a:
		e.add(a)
	if i in e:
		e.remove(i)
	if not e:
		ans += 1
print(ans)


n = int(input())
a = list(map(int, input().split()))
i = 0
q = 0
w = a[0]
while i < n:
	if i == w - 1:
		q = q + 1
		i = i + 1
		if i < n:
			w = a[i]
	else:
		i = i + 1
		if i < n:
			w = max(w, a[i])
print(q)


n = int(input())
a = list(map(int, input().split()))
d = 0
m = []
for i in range(n):
	m.append(a[i])
	while i + 1 in m:
		m.remove(i + 1)
	if not m:
		d += 1
print(d)


n = int(input())
cl = list(map(int, input().split()))
count = 0
i = 0
while i < n:
	pos = i + 1
	while i < pos:
		pos = max(pos, cl[i])
		i += 1
	count += 1
print(count)


n = int(input())
ai = [int(ai) for ai in input().split()]
AnsPage = ai[0]
Day = 0
for i in range(n):
	AnsPage = max(ai[i], AnsPage)
	if AnsPage == i + 1:
		Day += 1
print(Day)


import sys
num = int(sys.stdin.readline().strip())
ai = sys.stdin.readline().split(' ')
ai = list(map(lambda x: int(x), ai))
current_page = 1
ans = []
counter = 1
lastpage = ai[current_page - 1]
while lastpage <= num:
	while current_page != lastpage:
		counter = counter + 1
		current_page = current_page + 1
		if current_page > num:
			break
		lastpage = max(lastpage, ai[current_page - 1])
	ans.append(counter)
	counter = 1
	current_page = current_page + 1
	if current_page > num:
		break
	lastpage = max(lastpage, ai[current_page - 1])
print(len(ans))


n = int(input())
A = list(map(int, input().split()))
elem = A[0]
i = 0
answer = 0
while i < n:
	if A[i] > elem:
		elem = A[i]
	if elem <= i + 1:
		answer += 1
	i += 1
print(answer)


n = int(input())
l = [int(e) - 1 for e in input().split()]
p = 0
nb = 0
c = 0
while p < n:
	m = l[c]
	while c <= m:
		if l[c] > m:
			m = l[c]
		c += 1
	nb += 1
	p = m + 1
print(nb)


n = int(input())
l = list(map(int, input().split()))
c = 0
for x in range(n):
	if max(l[:x + 1]) == x + 1:
		c += 1
print(c)


a = int(input())
b = [int(i) - 1 for i in input().split()] + [0]
ans = 0
m = b[0]
for i in range(a):
	m = max(m, b[i])
	if i == m:
		ans += 1
		m = b[i + 1]
		continue
print(ans)


n = int(input())
l = list(map(int, input().split()))
c = 0
_ = 0
max = 0
while _ < n:
	if l[_] > max:
		max = l[_]
	if max == _ + 1:
		c = c + 1
		max = 0
	_ = _ + 1
if c == 0:
	print(1)
else:
	print(c)


page = input()
page = int(page)
secret = input().split()
day = 0
for i in range(0, page):
	secret[i] = int(secret[i])
i = 0
while i < page:
	x = max(secret[:i + 1]) - 1
	if i == x:
		day = day + 1
		i = i + 1
	else:
		i = x
print(day)


n = int(input())
page = [int(s) for s in input().split(' ')]
ans = 0
need = 0
for i in range(n):
	if need < page[i]:
		need = page[i]
	if page[i] == i + 1:
		if page[i] == need:
			ans += 1
print(ans)


a = int(input())
b = list(map(int, input().split()))
count = 0
now = 1
last_clue = 1
while a + 1 > now:
	last_clue = max(last_clue, b[now - 1])
	if last_clue <= now:
		count += 1
	now += 1
print(count)


gi = lambda : list(map(int, input().strip().split()))
(n,) = gi()
l = gi()
ans = 0
occ = [0] * (n + 1)
x = 0
ma = l[0] - 1
while x < n:
	ans += 1
	while x < ma:
		x += 1
		ma = max(ma, l[x] - 1)
	x += 1
	if x >= n:
		break
	ma = max(ma, l[x] - 1)
print(ans)


n = int(input())
lst = [int(i) for i in input().split()]
i = 0
nk = 0
nd = 0
while i < n:
	if nk < lst[i]:
		nk = lst[i]
	if nk == i + 1:
		nk = 0
		nd += 1
	i += 1
print(nd)


(n, a, ans, tem) = (int(input()), list(map(int, input().split())), 0, 0)
mem = [0] * (n + 1)
for i in range(n):
	if a[i] >= i + 1 and (not mem[a[i]]):
		mem[a[i]] = 1
		tem += 1
	if mem[i + 1]:
		tem -= 1
		mem[i + 1] = 0
	if not tem:
		ans += 1
print(ans)


import time
n = int(input())
a = [int(i) for i in input().split()]
start = time.time()
end = a[0]
ans = 0
for i in range(n):
	if a[i] > end:
		end = a[i]
	if end == i + 1:
		ans += 1
print(ans)
finish = time.time()


from sys import stdin
P = list(map(int, stdin.read().rstrip().split()))
(N, P) = (P[0], P[1:])
r = 0
c = 0
for i in range(N):
	if c == 0:
		r += 1
		c = P[i]
	c = max(c, P[i])
	if c <= i + 1:
		c = 0
print(r)


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


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


n = int(input())
a = list(map(int, input().split()))
i = 0
out = 0
while i < n:
	out += 1
	e = a[i] - 1
	while i <= e:
		if a[i] - 1 > e:
			e = a[i] - 1
		i += 1
print(out)


import os
import sys
import string
import math

def main(n, a):
	max_m = 0
	days = 0
	for i in range(n):
		max_m = max(max_m, a[i])
		if i + 1 >= max_m:
			days += 1
	return days

def parse():
	nums = int(input())
	a = list(map(int, input().split(' ')))
	return (nums, a)
print(main(*parse()))


n = int(input())
x = list(map(int, str(input()).split()))
r = 0
maxi = 0
for i in range(n):
	if maxi < x[i]:
		maxi = x[i]
	if maxi <= i + 1:
		r += 1
		maxi = 0
print(r)


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())
a = list(map(int, input().split()))
a.sort()
res = 0
for i in range(n):
	if i + 1 == a[i]:
		res += 1
print(res)


n = int(input())
a = list(map(int, input().split()))
mx = 0
nr = 0
for i in range(n):
	mx = max(mx, a[i])
	if i + 1 >= mx:
		nr += 1
print(nr)


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())
a = list(map(int, input().split()))
mystery = set()
ans = 0
for i in range(n):
	mystery.add(a[i])
	mystery.discard(i + 1)
	if len(mystery) == 0:
		ans += 1
print(ans)


N = int(input())
s = [int(x) for x in input().split()]
c = 0
temp = s[0]
flag = 0
for i in range(0, len(s)):
	if flag == 0:
		temp = s[i]
		flag = 1
	else:
		temp = max(temp, s[i])
	if temp <= i + 1:
		c = c + 1
		flag = 0
print(c)


import sys, math, queue
sys.setrecursionlimit(1000000)
n = int(input())
p = list(map(int, input().split()))
d = 0
mx = 1
for i in range(n):
	mx = max(mx, p[i])
	if i + 1 == mx:
		d += 1
if p[-1] != n:
	d += 1
print(d)


q = int(input())
w = list(map(int, input().split()))
n = 0
z = 0
for i in range(q):
	if w[i] - 1 > i:
		if z < w[i] - 1:
			z = w[i] - 1
	elif i == w[i] - 1 and i >= z:
		n += 1
print(n)


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)


N = int(input())
a = 0
b = list(map(int, input().split()))
c = 0
for i in range(N):
	c = max(c, b[i])
	if max(c, b[i]) == i + 1:
		a += 1
print(a)


n = int(input())
a = [int(x) for x in input().split()]
m = a[0]
day = 0
for i in range(n):
	if m < a[i]:
		m = a[i]
	if i + 1 == m:
		day += 1
print(day)


n = int(input())
A = list(map(int, input().split()))
ind = 0
ct = 0
while ind < len(A):
	curM = A[ind] - 1
	while curM > ind:
		ind += 1
		if A[ind] - 1 > curM:
			curM = A[ind] - 1
	ind += 1
	ct += 1
print(ct)


input()
days = 0
max_day = 0
for (i, b) in enumerate(map(int, input().split(' '))):
	days += int(max_day == i)
	max_day = max(max_day, b)
print(days)


n = int(input())
a = list(map(int, input().split()))
a = [0] + a
l = []
cur = 0
r = 0
ans = 0
vis = []
m = 0
for i in range(1, n + 1):
	m = max(m, a[i])
	if m == i:
		ans += 1
print(ans)


n = int(input())
arr = [int(x) for x in input().split()]
day = 0
max_ = 0
for i in range(n):
	if arr[i] == i + 1 and i + 1 >= max_:
		day = day + 1
	max_ = max(max_, arr[i])
print(day)


input()
r = m = i = 0
for x in map(int, input().split()):
	i += 1
	m = max(m, x)
	if m == i:
		r += 1
print(r)


n = int(input())
a = list(map(int, input().split()))
c = 0
ma = 0
for i in range(n):
	if ma < a[i]:
		ma = a[i]
	if ma == i + 1:
		c += 1
print(c)


n = int(input())
str = input()
a = str.split()
ma = 0
cnt = 0
for i in range(0, n):
	ma = max(int(a[i]), ma)
	if ma == i + 1:
		cnt += 1
print(cnt)


import sys
input = sys.stdin.readline
n = int(input())
a = list(map(int, input().split()))
(mx, res) = (0, 0)
for i in range(len(a)):
	mx = max(mx, a[i])
	res += i + 1 == mx
print(res)


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


n = int(input())
a = list(map(int, input().split()))
s = set()
r = 0
for (i, item) in enumerate(a):
	if item == i + 1 and (len(s) == 0 or max(s) <= i + 1):
		r += 1
		s = set()
	else:
		s.add(item)
print(r)


n = int(input())
arr = [int(i) for i in input().split()]
(c, i) = (0, 0)
while i < n:
	c += 1
	m = arr[i]
	while arr[i] != m or m != i + 1:
		i += 1
		if m < arr[i]:
			m = arr[i]
	i += 1
print(c)


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


n = int(input())
a = [int(s) for s in input().split()]
ans = 0
dc = 0
while dc < n:
	dc += 1
	de = a[dc - 1]
	while de > dc:
		dc_st = dc
		for dc in range(dc_st, de + 1):
			if a[dc - 1] > de:
				de = a[dc - 1]
	ans += 1
print(ans)


n = int(input())
arr = list(map(int, input().split()))
p = 0
s = 0
while p + 1 <= n:
	p += 1
	m = arr[p - 1]
	while p <= m:
		m = max(m, arr[p - 1])
		p += 1
	p -= 1
	s += 1
print(s)


import sys
from collections import defaultdict
strInp = lambda : input().strip().split()
intInp = lambda : list(map(int, strInp()))
n = int(input())
arr = intInp()
c = 0
m = 0
for i in range(n):
	m = max(m, arr[i])
	if i + 1 >= m:
		c += 1
print(c)


n = int(input())
a = list(map(int, input().split()))
record = {}
for i in range(n):
	record[i + 1] = a[i]
myst = n
i = 1
day = 0
while myst > 0:
	j = record[i]
	while i < j or i < record[i]:
		if record[i] > j:
			j = record[i]
		i += 1
		myst -= 1
	day += 1
	myst -= 1
	i += 1
print(day)


n = int(input())
a = list(map(int, input().split()))
c = 0
i = 0
while i < n:
	j = a[i] - 1
	while i < j:
		i += 1
		if a[i] - 1 > j:
			j = a[i] - 1
	c += 1
	i += 1
print(c)


import math
import bisect
import itertools
import sys
I = lambda : sys.stdin.readline()
mod = 10 ** 9 + 7

def modu(a, m):
	if a % m:
		return a % m
	return m

def mindiff(a):
	b = a[:]
	b.sort()
	m = 10000000000
	for i in range(len(b) - 1):
		if b[i + 1] - b[i] < m:
			m = b[i + 1] - b[i]
	return m

def lcm(a, b):
	return a * b // math.gcd(a, b)

def merge(a, b):
	i = 0
	j = 0
	c = 0
	ans = []
	while i < len(a) and j < len(b):
		if a[i] < b[j]:
			ans.append(a[i])
			i += 1
		else:
			ans.append(b[j])
			c += len(a) - i
			j += 1
	ans += a[i:]
	ans += b[j:]
	return (ans, c)

def mergesort(a):
	if len(a) == 1:
		return (a, 0)
	mid = len(a) // 2
	(left, left_inversion) = mergesort(a[:mid])
	(right, right_inversion) = mergesort(a[mid:])
	(m, c) = merge(left, right)
	c += left_inversion + right_inversion
	return (m, c)

def is_prime(num):
	if num == 1:
		return False
	if num == 2:
		return True
	if num == 3:
		return True
	if num % 2 == 0:
		return False
	if num % 3 == 0:
		return False
	t = 5
	a = 2
	while t <= int(math.sqrt(num)):
		if num % t == 0:
			return False
		t += a
		a = 6 - a
	return True

def ceil(a, b):
	if a % b == 0:
		return a // b
	else:
		return a // b + 1

def ncr1(n, r):
	s = 1
	for i in range(min(n - r, r)):
		s *= n - i
		s %= mod
		s *= pow(i + 1, mod - 2, mod)
		s %= mod
	return s
n = int(input())
a = [0] + list(map(int, input().split()))
ans = 0
m = a[1]
for i in range(1, n + 1):
	m = max(m, a[i])
	if m == i:
		ans += 1
		m = 0
print(ans)


n = int(input())
array = input()
A = [int(x) for x in array.split()]
counter = 0
max_have_to_finish = A[0]
for i in range(n):
	if A[i] >= max_have_to_finish:
		max_have_to_finish = A[i]
	if i + 1 >= max_have_to_finish:
		counter += 1
print(counter)


n = int(input())
lst = list(map(int, input().split()))
maxm = 0
count = 0
for i in range(1, n + 1):
	if lst[i - 1] == i:
		if maxm <= lst[i - 1]:
			count += 1
	else:
		maxm = max(maxm, lst[i - 1])
print(count)


n = int(input())
a = [int(i) for i in input().split()]
page = a[0]
i = 0
c = 0
while i != n:
	while i != page - 1:
		i += 1
		page = max(page, a[i])
	i += 1
	if i != n:
		page = a[i]
	c += 1
print(c)


n = int(input())
substrs = input().split()
array = [int(x) for x in substrs]
days = 0
max_page = array[0]
i = 1
while True:
	if i == max_page:
		days += 1
		if i == len(array):
			break
		max_page = array[i]
	else:
		max_page = max(max_page, array[i])
	i += 1
print(days)


import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, random, time, copy, functools
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20
eps = 1.0 / 10 ** 10
mod = 10 ** 9 + 7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]

def LI():
	return [int(x) for x in sys.stdin.readline().split()]

def LI_():
	return [int(x) - 1 for x in sys.stdin.readline().split()]

def LF():
	return [float(x) for x in sys.stdin.readline().split()]

def LS():
	return sys.stdin.readline().split()

def I():
	return int(sys.stdin.readline())

def F():
	return float(sys.stdin.readline())

def S():
	return input()

def pf(s):
	return print(s, flush=True)

def main():
	n = I()
	a = LI_()
	r = 0
	m = 0
	for i in range(n):
		if m < a[i]:
			m = a[i]
		if i >= m:
			r += 1
	return r
print(main())


amount = int(input())
array = [int(s) for s in input().split()]
counter = 0
curr = -1
for i in range(len(array)):
	curr = max(array[i], curr)
	if curr == i + 1:
		counter += 1
print(counter)


(n, s) = (int(input()), [*map(int, input().split())])
(res, curent, tmp) = (0, 0, 0)
while curent < n:
	tmp = max(tmp, s[curent])
	curent += 1
	if tmp == curent:
		res += 1
		tmp = 0
print(res)


def ans(arr):
	i = 1
	cnt = 0
	while i <= n:
		cnt += 1
		mx = i
		while i <= n and i <= mx:
			mx = max(mx, arr[i - 1])
			i += 1
	return cnt
n = int(input())
a = list(map(int, input().strip().split()))
print(ans(a))


n = int(input())
a = list(map(int, input().split()))
op = []
sol = 0
if n == 1:
	print(1)
else:
	for i in range(n):
		op.append(a[i])
		j = 0
		while j < len(op):
			if op[j] == i + 1:
				op.pop(j)
			else:
				j += 1
		if not len(op):
			sol += 1
	print(sol)


from sys import stdin
input = stdin.readline
n = int(input())
a = list(map(int, input().split()))
i = 0
stop = 0
cnt = 0
while i < n:
	stop = max(stop, a[i])
	if i + 1 >= stop:
		cnt += 1
	i += 1
print(cnt)


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)


days = 0
pages = int(input())
sols = map(int, input().split())
last = 1
for (p, s) in enumerate(sols):
	last = max(last, s)
	if p + 1 == last:
		days += 1
print(days)


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


import collections, atexit, math, sys, bisect
sys.setrecursionlimit(1000000)
isdebug = False
try:
	import pylint
	import numpy

	def dprint(*args, **kwargs):
		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())
if isdebug and len(sys.argv) == 1:
	red_inout()

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

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


def findit(a, i):
	while i != a[i] - 1:
		i = a[i] - 1
	return i
n = int(input())
a = [int(i) for i in input().split()]
i = 0
ans = 0
while i <= len(a) - 1:
	ind = a[i] - 1
	e = i
	while e <= ind:
		ind = max(ind, findit(a, a[e] - 1))
		e += 1
	i = ind + 1
	ans += 1
print(ans)


n = int(input())
a = list(map(int, input().split()))
a = [x - 1 for x in a]
read = [False for x in range(n)]
i = 0
days = 0
total = n
current = -1
for (i, x) in enumerate(a):
	if i > current:
		days += 1
	current = max(x, current)
print(days)


import sys
import math
import bisect

def solve(A):
	n = len(A)
	i = 0
	ans = 0
	while i < n:
		ans += 1
		max_ref = A[i]
		i += 1
		while i < n and i < max_ref:
			max_ref = max(max_ref, A[i])
			i += 1
	return ans

def main():
	n = int(input())
	A = list(map(int, input().split()))
	print(solve(A))
main()


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


input()
X = list(map(int, input().split()))
Y = [False for i in range(len(X))]
Count = 0
while Y.count(True) != len(Y):
	i = Y.index(False)
	MAX = X[i] - 1
	while i < len(X) and (not Y[i]) and (i <= MAX):
		(Y[i], MAX, i) = (True, max(MAX, X[i] - 1), i + 1)
	Count += 1
print(Count)


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)


from itertools import accumulate
n = int(input())
max_pages = [0] + list(accumulate(map(int, input().split(' ')), max))
print(sum((int(max_pages[i] == i) for i in range(n))))


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


n = int(input())
L = [int(x) - 1 for x in input().split()]
currentPage = 0
latestMystery = 0
days = 0
while currentPage < n:
	days += 1
	latestMystery = L[currentPage]
	while latestMystery > currentPage:
		temp = currentPage
		currentPage = latestMystery
		for i in range(temp, max(temp, latestMystery) + 1):
			latestMystery = max(L[i], latestMystery)
	currentPage += 1
print(days)


n = int(input())
m = 0
d = 0
for (i, p) in enumerate(map(int, input().split()), 1):
	m = max(m, p)
	if i == m:
		d += 1
print(d)


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


num = int(input())
str = input()
p = []
for s in str.split():
	if s.isdigit():
		p.append(int(s))
val = p[0]
day = 0
for i in range(num):
	if p[i] > val:
		val = p[i]
	if val == i + 1 or i + 1 == num:
		day += 1
print(day)


n = int(input())
a = list(map(int, input().split()))
kq = 0
i = 0
while i < n:
	j = i + 1
	tem = []
	tem.append(a[i])
	ln = max(tem)
	while i + 1 < ln:
		i += 1
		tem.append(a[i])
		ln = max(tem)
	kq += 1
	i += 1
print(kq)


n = int(input())
my_list = list(map(int, input().split()))
counter = 0
current_max = my_list[counter]
for i in range(n):
	if my_list[i] > current_max:
		current_max = my_list[i]
	if i + 1 == current_max:
		counter += 1
		if current_max != n:
			current_max = my_list[i + 1]
print(counter)


n = int(input())
a = [int(x) for x in input().split()]
days = 0
start = 1
end = a[start - 1]
maxend = end
while start <= n:
	i = start
	end = a[start - 1]
	if end > maxend:
		maxend = end
	while i <= maxend:
		end = a[i - 1]
		if end > maxend:
			maxend = end
		i += 1
	start = i
	days += 1
print(days)


n = int(input())
a = list(map(int, input().split()))
cur = a[0]
cnt = 0
for i in range(n):
	if a[i] == i + 1 and a[i] >= cur:
		cnt += 1
	else:
		cur = max(cur, a[i])
print(cnt)


n = int(input())
pages = list(map(int, input().split()))
days = 0
barrier = 0
for i in range(len(pages)):
	barrier = max(barrier, pages[i])
	if i + 1 == barrier:
		days += 1
print(days)


n = int(input())
a = list(map(int, input().split()))
ans = 0
cur = 0
while cur < n:
	tmp = cur
	mx = a[cur]
	while mx > tmp + 1 and tmp < n:
		tmp += 1
		mx = max(mx, a[tmp])
	ans += 1
	cur = tmp + 1
print(ans)


n = int(input())
pages = map(int, input().split())
days = 0
last_page = 0
for (i, page) in enumerate(pages, 1):
	last_page = max(last_page, page)
	if last_page <= i:
		days += 1
print(days)


input()
d = x = 0
for (i, a) in enumerate(map(int, input().split()), 1):
	x = max(x, a)
	d += x == i
print(d)


n = int(input())
(ans, m, i) = (0, 0, 0)
for x in map(int, input().split()):
	m = max(m, x)
	i += 1
	if m == i:
		ans += 1
print(ans)


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


n = int(input())
ar = list(map(int, input().split()))
mx = int(0)
ans = int(0)
for now in range(0, n):
	mx = max(ar[now], mx)
	if mx == now + 1:
		ans += 1
		mx = 0
if mx == 0:
	print(ans)
else:
	print(ans + 1)


n = int(input())
X = 0
C = 0
p = input().rstrip().split(' ')
i = 0
F = 0
while i <= len(p):
	if i == len(p):
		break
	T = int(p[i])
	C = p[F:T]
	C.sort(key=int, reverse=True)
	i = int(C[0])
	while i > T:
		T = i
		C = p[F:T]
		C.sort(key=int, reverse=True)
		i = int(C[0])
	F = i
	X += 1
print(X)


n = int(input())
a = [int(x) - 1 for x in input().strip().split()]
i = 0
maxmist = -1
count = 0
while i < n:
	maxmist = max(maxmist, a[i])
	if maxmist <= i:
		count += 1
		maxmist = -1
	i += 1
print(count)


ent = int(input())
val = input().split()
valn = []
iguais = []
ct = 0
aux = int(val[0])
for num in val:
	valn.append(int(num))
for num in range(1, ent + 1):
	if valn[num - 1] > aux:
		aux = valn[num - 1]
	if aux < num + 1:
		ct += 1
print(ct)


def solve_it(n, mexpl):
	days = 0
	cp = 0
	while cp < len(mexpl):
		lastmistery = mexpl[cp]
		while lastmistery - 1 >= cp and cp < len(mexpl):
			lastmistery = mexpl[cp] if mexpl[cp] > lastmistery else lastmistery
			cp += 1
		days += 1
	return days
n = int(input())
mexpl = list(map(int, input().split()))
print(solve_it(n, mexpl))


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


q = set()
n = int(input())
a = input().split(' ')
k = 0
for i in range(1, n + 1):
	j = str(i)
	if j in q:
		q.remove(j)
	if a[i - 1] != j:
		q.add(a[i - 1])
	if len(q) == 0:
		k += 1
print(k)


n = int(input())
kitap = list(map(int, input().split()))
gun = 0
kadar = kitap[0]
for i in range(n):
	if kitap[i] > kadar:
		kadar = kitap[i]
	if i + 1 == kadar:
		gun += 1
print(gun)


t = int(input())
b = list(map(int, input().split()))
p = 0
c = 0
for j in range(t):
	if j + 1 == max(p, b[j]):
		c += 1
		p = max(p, b[j])
	else:
		p = max(p, b[j])
print(c)


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)


from math import *
from collections import *
import sys
sys.setrecursionlimit(10 ** 9)
n = int(input())
a = list(map(int, input().split()))
m = 0
ct = 0
for i in range(n):
	if a[i] >= m and a[i] == i + 1:
		ct += 1
		m = 0
	else:
		m = max(m, a[i])
print(ct)


import math
from collections import deque, defaultdict
from sys import stdin, stdout
listin = lambda : list(map(int, input().split()))
mapin = lambda : map(int, input().split())
n = int(input())
a = listin()
k = -1
count = 0
for i in range(n):
	k = max(k, a[i] - 1)
	if k == i:
		count += 1
print(count)


n = int(input())
a = [int(i) for i in input().split()]
k = 0
for i in range(n):
	m = max(a[:i + 1])
	if i + 1 == m:
		k += 1
print(k)


n = int(input())
arr = [int(x) for x in input().split()]
days = 0
mx = 0
for (i, a) in enumerate(arr):
	mx = max(mx, a)
	if mx == i + 1:
		days += 1
print(days)


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())
A = list(map(int, input().split()))
count = 0
visited = [0 for i in range(n)]
mx = 0
for i in range(n):
	if visited[i] == 0:
		count += 1
	if A[i] > i + 1:
		for j in range(max(mx, i + 1), A[i]):
			visited[j] = 1
	mx = max(mx, A[i])
print(count)


n = int(input())
p = [0, *map(int, input().split())]
days = 0
thismax = 0
for i in range(1, n + 1):
	thismax = max(thismax, p[i])
	if thismax == i:
		days += 1
print(days)


def main():
	n = int(input())
	mystery = list(map(int, input().split()))
	nums = set()
	days = 0
	val = mystery[0]
	for i in range(n):
		if mystery[i] == i + 1:
			if mystery[i] >= val:
				days += 1
				val = mystery[i]
		elif mystery[i] > val:
			val = mystery[i]
	print(days)
main()


def main():
	n = int(input())
	a = [0] + list(map(int, input().split(' ')))
	right = 1
	ans = 0
	for i in range(1, n + 1):
		right = max(right, a[i])
		if i == right:
			ans += 1
	print(ans)
exit(main())


n = int(input())
l = [int(x) for x in input().split()]
days = 0
target = 0
for i in range(n):
	target = max(target, l[i])
	if i + 1 >= target:
		days += 1
print(days)


n = int(input())
a = [int(x) for x in input().split()]
start = 0
days = 0
while start < len(a):
	curr_limit = a[start] - 1
	while start <= curr_limit:
		if a[start] - 1 > curr_limit:
			curr_limit = a[start] - 1
		start += 1
	days += 1
print(days)


length_of_book = int(input())
explanations = [int(i) for i in input().split(' ')]
days = 0
greatest = 0
for (index, i) in enumerate(explanations):
	if i > greatest:
		greatest = i
	if greatest == index + 1:
		days += 1
print(days)


n = int(input())
A = list(map(int, input().split()))
B = []
count = 0
a = 0
for i in range(n):
	B.append(A[i])
	a = max(B)
	if a == i + 1:
		count += 1
print(count)


n = int(input())
a = [int(x) for x in input().rstrip().split()]
r = 0
i = 0
while i < n:
	r += 1
	max = a[i]
	while i < n and i + 1 < max:
		i += 1
		if a[i] > max:
			max = a[i]
	i += 1
print(r)


n = int(input())
s_a = input().split()
a = []
for i in range(0, n):
	a.append(int(s_a[i]))
read = a[0]
days = 0
for page in range(0, n):
	if read < a[page]:
		read = a[page]
	if read > page + 1:
		pass
	else:
		days += 1
print(days)


n = int(input())
a = list(map(int, input().split()))
mx = a[0]
days = 0
for i in range(n):
	if mx < a[i]:
		mx = a[i]
	elif mx == i + 1:
		days += 1
		if i < n - 1:
			mx = a[i + 1]
print(days)


import sys

class Main:

	def __init__(self):
		self.buff = None
		self.index = 0

	def next(self):
		if self.buff is None or self.index == len(self.buff):
			self.buff = sys.stdin.readline().split()
			self.index = 0
		val = self.buff[self.index]
		self.index += 1
		return val

	def next_int(self):
		return int(self.next())

	def cal(self, s):
		if len(s) == 1:
			return s[0]
		if s[0] == 0:
			return self.cal(s[1:])
		v = 1
		for c in s:
			v *= c
		return v

	def solve(self):
		n = self.next_int()
		d = 0
		nd = {}
		for i in range(1, n + 1):
			x = self.next_int()
			if i in nd:
				nd.pop(i)
			if x > i:
				nd[x] = True
			if len(nd) == 0:
				d += 1
		print(d)
Main().solve()


n = int(input())
nums = [int(x) - 1 for x in input().split()]
i = 0
m = -1
res = 0
while i < n:
	res += 1
	m = max(nums[i], m)
	while i < m:
		i += 1
		m = max(nums[i], m)
	i += 1
print(res)


n = int(input())
arr = [int(p) for p in input().split()]
i = 0
curr = 0
count = 0
while i < len(arr):
	curr = max(arr[i], curr)
	j = curr
	while i < j:
		curr = max(arr[i], curr)
		i += 1
		j = curr
	count += 1
print(count)


n = int(input())
a = list(map(int, input().split()))
days = 0
mys = []
for i in range(1, n + 1):
	mys.append(a[i - 1])
	ll = len(mys)
	j = 0
	while j < ll:
		if mys[j] == i:
			del mys[j]
			ll -= 1
			continue
		j += 1
	if len(mys) == 0:
		days += 1
print(days)


n = int(input())
a = list(map(int, input().strip().split()))
a.sort()
c = 0
for i in range(n):
	if i + 1 == a[i]:
		c = c + 1
if n != a[-1]:
	c = c + 1
print(c)


n = int(input())
L = [int(i) for i in input().split()]
F = [0] * (n + 1)
s = 0
maxx = 0
for i in range(len(L)):
	if i + 1 > maxx:
		maxx = max(i + 1, L[i])
		s += 1
	else:
		maxx = max(L[i], maxx)
print(s)


n = int(input())
lst = list(map(int, input().split()))
(res, mx) = (0, 0)
for (i, x) in enumerate(lst):
	mx = max(mx, x)
	if mx <= i + 1:
		res += 1
		mx = 0
print(res)


b = int(input())
a = [int(x) for x in input().split()]
n = b
page = a
(i, d) = (0, 0)

def read():
	global i
	while max(page[:i]) > i:
		i = max(page[:i])
while i < n:
	i += 1
	d += 1
	read()
print(d)


def main():
	n = int(input())
	arr = list(map(int, input().split()))
	last_page = 0
	count = 0
	while last_page < n:
		max_page = last_page
		while last_page <= max_page:
			tmp_page = arr[last_page] - 1
			if tmp_page > max_page:
				max_page = tmp_page
			last_page += 1
		count += 1
	return count
print(main())


import sys
sys.setrecursionlimit(2000)
from collections import Counter
from functools import reduce
n = [int(val) for val in sys.stdin.readline().split()][0]
a = [int(val) for val in sys.stdin.readline().split()]
days = 0
mysteries = set([])
pages = set([val for val in range(n)])
for page in range(n):
	if len(mysteries) == 0:
		days += 1
	if page in mysteries:
		mysteries.remove(page)
	new_page = a[page] - 1
	if new_page > page:
		mysteries.add(new_page)
print(days)


n = int(input())
a = list(map(int, input().split()))
k = 0
q = 0
w = 0
while q <= n - 1:
	i = q
	w = q
	if a[i] > q + 1:
		w = a[i] - 1
		while i != w:
			i += 1
			if a[i] > w:
				w = a[i] - 1
	q = w
	k += 1
	q += 1
print(k)


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


n = int(input())
l = list(map(int, input().split()))
count = 0
m = 0
for i in range(n):
	if l[i] > m:
		m = l[i]
	if m == i + 1:
		count += 1
print(count)


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
sys.setrecursionlimit(10 ** 5 + 1)
inf = int(10 ** 20)
max_val = inf
min_val = -inf
RW = lambda : sys.stdin.readline().strip()
RI = lambda : int(RW())
RMI = lambda : [int(x) for x in sys.stdin.readline().strip().split()]
RWI = lambda : [x for x in sys.stdin.readline().strip().split()]
lens = RI()
pages = RMI()
days = 0
need = 1
for (i, v) in enumerate(pages):
	need = max(need, v)
	days += need == i + 1
print(days)


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)


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


a = input()
lst = [int(x) for x in input().split()]
ans = 0
temp = 0
for i in range(int(a)):
	if temp < lst[i]:
		temp = lst[i]
	if i + 1 < temp:
		continue
	ans += 1
print(ans)


n = int(input())
a = [int(i) - 1 for i in input().split()]
(m, d, i) = (0, 0, 0)
while i < n:
	(d, m) = (d + 1, i)
	while i < n and i <= m:
		m = max(m, a[i])
		i += 1
print(d)


n = int(input())
a = list(map(int, input().split()))
count = 1
temp = a[0]
for i in range(1, n):
	if i + 1 > temp:
		count += 1
		temp = a[i]
	elif a[i] > temp:
		temp = a[i]
print(count)


n = int(input())
ns = list(map(int, input().split()))
count = 0
tmp = 0
for (i, v) in enumerate(ns):
	tmp = tmp if tmp > v else v
	if tmp == i + 1:
		count += 1
print(count)


n = int(input().strip())
nums = map(int, input().strip().split())
cnt = idx = mx = 0
for (idx, num) in enumerate(nums, 1):
	if num < mx:
		continue
	else:
		mx = num
	if idx == mx:
		cnt += 1
		mx = 0
	idx += 1
print(cnt)


n = int(input())
a = [int(i) for i in input().split()]
k = 0
mx = -1000000000.0
for i in range(n):
	mx = max(a[:i + 1])
	if i + 1 == mx:
		k += 1
print(k)


n = int(input())
a = [None] + list(map(int, input().split()))
day = 1
page = 1
nextStop = a[page]
while True:
	while page < nextStop:
		page += 1
		nextStop = max(nextStop, a[page])
	if page == n:
		break
	day += 1
	page += 1
	nextStop = max(nextStop, a[page])
print(day)


import math
import random
import sys
from collections import defaultdict as dd
mod = 7 + 10 ** 9
n = int(input())
l = [int(i) for i in input().split()]
ans = 0
i = 0
due = set()
while i < n:
	due.add(l[i])
	if i + 1 in due:
		due.remove(i + 1)
	if len(due) == 0:
		ans += 1
	i += 1
if ans == 0:
	ans = 1
print(ans)


n = int(input())
p = list(map(int, input().split()))
day = pages = 0
for i in range(n):
	pages = max(p[i], pages)
	if pages == i + 1:
		day += 1
	elif pages > i + 1:
		continue
print(day)


n = int(input())
a = list(map(int, input().split(' ')))
Max = 1
i = 1
days = 0
while i <= n:
	j = a[i - 1]
	Max = max(Max, j)
	if i >= Max:
		days += 1
	i += 1
print(days)


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)


import sys
try:
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
except:
	pass
from collections import defaultdict
n = int(input())
a = [int(x) for x in input().split()]
days = 0
page = {}
p = 1
for ele in a:
	page[p] = ele
	p += 1
visited = defaultdict(lambda : False)
end = 1
for p in range(1, n + 1):
	if not visited[p]:
		days += 1
	if page[p] >= end:
		end = page[p]
		for i in range(p, page[p] + 1):
			visited[i] = True
print(days)


input()
l = list(map(int, input().split()))
d = 0

def read():
	global d
	for i in range(len(l)):
		if max(l[0:i + 1]) == i + 1:
			d += 1
read()
print(d)


digl = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']
ii = lambda : int(input())
si = lambda : input()
dgl = lambda : list(map(int, input()))
f = lambda : map(int, input().split())
il = lambda : list(map(int, input().split()))
ls = lambda : list(input())
mod = 10 ** 9 + 7
n = ii()
l = il()
(pages, days) = (0, 0)
for i in range(n):
	pages = max(pages, l[i])
	if pages == i + 1:
		days += 1
print(days)


n = int(input())
a = [int(i) for i in input().split()]
count = 1
ma = a[0]
for i in range(n - 1):
	ma = max(a[i], ma)
	if i + 1 < ma:
		continue
	else:
		count = count + 1
		ma = a[i + 1]
print(count)


n = int(input())
a = list(map(int, input().split()))
cur_max = 0
ans = 0
for i in range(n):
	j = i + 1
	if a[i] > cur_max:
		cur_max = a[i]
	if j == cur_max:
		ans += 1
print(ans)


sum = 0
maximum = 0
stran = int(input())
zag = [int(x) for x in input().split()]
for i in range(stran):
	maximum = max(maximum, zag[i])
	if maximum <= i + 1:
		sum += 1
print(sum)


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)


n = int(input())
pages = list(map(int, input().split(' ')))
days = 0
max_page = pages[0]
for i in range(n):
	if pages[i] > max_page:
		max_page = pages[i]
	if max_page == i + 1:
		days = days + 1
print(days)


n = int(input())
a = [int(x) for x in input().split()]
t = set()
r = 0
for (i, c) in enumerate(a, 1):
	if len(t) == 0:
		r += 1
	t.add(c)
	if i in t:
		t.remove(i)
print(r)


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


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


import sys

def main():
	n = int(sys.stdin.readline())
	arr = [int(i) for i in sys.stdin.readline().split()]
	num = 0
	current_right = 0
	for i in range(len(arr)):
		if arr[i] - 1 > current_right:
			current_right = arr[i] - 1
		if current_right == i:
			num += 1
	print(num)
main()


n = int(input())
l = list(map(int, input().split()))
(ans, m, j) = (0, 0, 0)
for i in l:
	m = max(m, i)
	j += 1
	if m == j:
		ans += 1
print(ans)


n = int(input())
arr = list(map(int, input().split()))
days = 0
i = 0
while i < len(arr):
	days += 1
	target = arr[i]
	while i < target:
		if arr[i] > target:
			target = arr[i]
		i += 1
print(days)


N = int(input())
pg = [int(i) for i in input().split()]
pg.insert(0, 0)
currMax = pg[1]
days = 0
for i in range(1, N + 1):
	if pg[i] > currMax:
		currMax = pg[i]
	if i == currMax:
		days = days + 1
print(days)


n = int(input())
a = list(map(int, input().split()))
i = 0
cnt = 0
while i < n:
	cnt += 1
	x = a[i]
	while i < x:
		x = max(x, a[i])
		i += 1
print(cnt)


n = int(input())
a = list(map(int, input().split()))
day = 0
i = 0
goto = a[i]
while i < n:
	if a[i] > goto:
		goto = a[i]
	if i + 1 == a[i] and goto == a[i]:
		day += 1
	i += 1
print(day)


n = int(input())
a = [int(x) for x in input().split()]
(c, k) = (0, 0)
for i in range(n):
	k = max(k, a[i])
	if k == i + 1:
		c += 1
print(c)


(n, a) = (int(input()), [0] + list(map(int, input().split())))
cnt = 0
maxpage = 1
for i in range(1, n + 1):
	maxpage = max(maxpage, a[i])
	if i >= maxpage:
		cnt += 1
print(cnt)


n = int(input())
a = list(map(int, input().split()))
(steck, s) = ([], 0)
for i in range(n):
	if a[i] not in steck:
		steck.append(a[i])
	if i + 1 in steck:
		del steck[steck.index(i + 1)]
	if len(steck) == 0:
		s += 1
print(s)


n = int(input())
a = [int(i) for i in input().split()]
x = 0
nxt = 0
for (i, j) in enumerate(a):
	if nxt < j:
		nxt = j
	if nxt == i + 1:
		x = x + 1
print(x)


n = input()
book = list(map(int, input().split()))
mysteries = []
days = 0
for (page, mystery) in enumerate(book):
	if mystery not in mysteries:
		mysteries.append(mystery)
	if page + 1 in mysteries:
		mysteries.remove(page + 1)
	if len(mysteries) == 0:
		days += 1
print(days)


import sys
import heapq

def solve(n, data):
	day = 0
	i = 0
	li = []
	i += 1
	li.append(data[0])
	heapq.heapify(li)
	while i <= n:
		while li:
			if li[0] <= i:
				li.pop(0)
			else:
				i += 1
				heapq.heappush(li, data[i - 1])
		day += 1
		i += 1
		if i <= n:
			heapq.heappush(li, data[i - 1])
	if li:
		day += 1
	return day
n = int(input())
data = list(map(int, input().split()))
print(solve(n, data))


n = int(input())
arr = [int(x) for x in input().split()]
answer = 0
max_index = 0
for i in range(n):
	max_index = max(max_index, arr[i] - 1)
	if max_index <= i:
		answer += 1
print(answer)


n = int(input())
l = list(map(int, input().split()))
(f, k) = (0, set())
for i in range(1, n + 1):
	k.add(l[i - 1])
	if i in k:
		k.discard(i)
		if len(k) == 0:
			f += 1
print(f)


N = int(input())
ls = list(map(int, input().split()))
cnt = 0
Max = ls[0]
for i in range(N):
	Max = max(Max, ls[i])
	if ls[i] == i + 1 and ls[i] >= Max:
		cnt += 1
print(cnt)


for _ in range(1):
	n = int(input())
	l = list(map(int, input().split()))
	c = 0
	l = [0] + l
	i = 1
	while i <= n:
		c += 1
		ma = i
		while i <= n and i <= ma:
			ma = max(ma, l[i])
			i += 1
	print(c)


(n, a) = (int(input()), list(map(lambda _: int(_) - 1, input().split())))
(c, d) = (0, 0)
while c < n:
	m = a[c]
	while m > c:
		c += 1
		m = max(m, a[c])
	c += 1
	d += 1
print(d)


def lol(x):
	while x < max(a[:x]):
		x = max(a[:x])
	return x
n = int(input())
a = list(map(int, input().split()))
l = a[-1]
m = p = 0
while m != l:
	m += 1
	m = lol(a[m - 1])
	p += 1
print(p)


def get_number_of_days(pages):
	n_days = 0
	max_page = 0
	for (i, page) in enumerate(pages):
		if page > max_page:
			max_page = page
		if not max_page > i + 1:
			n_days += 1
			max_page = 0
	return n_days
n = input()
pages = [int(x) for x in input().split(' ')]
print(get_number_of_days(pages))


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


N = int(input())
A = list(map(int, input().split()))
day = 1
currentDayReadablePage = 1
for n in range(N - 1):
	currentDayReadablePage = max(currentDayReadablePage, A[n])
	if currentDayReadablePage <= n + 1:
		day += 1
print(day)


n = int(input())
a = list(map(int, input().split()))
a = [e - 1 for e in a]
read = set()
need = set()
p = 0
res = 0
while p < n:
	read.add(p)
	need.add(p)
	need.add(a[p])
	if read == need:
		res += 1
		read.clear()
		need.clear()
	p += 1
print(res)


n = int(input())
array = [int(x) for x in input().split()]
days = 0
till = 0
for i in range(len(array)):
	till = max(till, array[i])
	if array[i] == i + 1 and till <= i + 1:
		days += 1
print(days)


n = int(input())
tab = [int(i) for i in input().split(' ')]
maxn = 1
time = 0
for i in range(n):
	maxn = max(maxn, tab[i])
	if i + 1 == maxn:
		time += 1
print(time)


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


n = int(input())
a = [0] + list(map(int, input().split()))
days = 0
q = {}
c = 0
for i in range(1, n + 1):
	if i in q:
		c -= 1
		q.pop(i, None)
	if a[i] == i and len(q) == 0:
		days += 1
	elif a[i] != i:
		q[a[i]] = 1
print(days)


from collections import defaultdict
from functools import reduce
mi = lambda : [int(i) for i in input().split()]
flat = lambda l: reduce(lambda a, b: a + b, l)
n = mi()[0]
a = [0] + mi()
r = 0
i = 1
gt = 0
while i <= n:
	if a[i] == i:
		r += 1
		i += 1
		continue
	while i < gt or a[i] != i:
		gt = max(a[i], gt)
		i += 1
print(r)


n = int(input())
s = input().split(' ')
d = 0
lastpage = 0
for i in range(n):
	lastpage = max(lastpage, int(s[i]))
	if i + 1 == lastpage:
		d += 1
		lastpage = 0
print(d)


(n, ls, d, md) = (int(input()), map(int, input().split()), 0, 1)
for (i, v) in enumerate(ls):
	if v > md:
		md = v
	if md == i + 1:
		(md, d) = (md + 1, d + 1)
print(d)


import sys

def rint():
	return map(int, sys.stdin.readline().split())
n = int(input())
a = list(rint())
a = [0] + a
m = 0
cnt = 0
for i in range(1, n + 1):
	m = max(m, a[i])
	if m <= i:
		cnt += 1
print(cnt)


n = input()
n = int(n)
a = input().split()
for i in range(n):
	a[i] = int(a[i])
mx = -1
cnt = 0
for i in range(n):
	mx = max([mx, a[i]])
	if mx == i + 1:
		cnt += 1
		mx = -1
if mx != -1:
	cnt += 1
print(cnt)


n = int(input())
books = list(map(int, input().split()))
day = 0
error = 0
for i in range(n):
	if i + 1 == books[i] and (error == 0 or error <= books[i]):
		day += 1
	elif i + 1 < books[i]:
		temp = error
		lol = books[i]
		error = max(lol, temp)
print(day)


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


n = int(input())
a = [int(a) for a in input().split()]
k = 0
ans = set()
for j in range(n):
	ans.add(a[j])
	if j + 1 in ans:
		ans.remove(j + 1)
	if len(ans) == 0:
		k += 1
print(k)


import sys
from bisect import bisect_left, bisect_right
from collections import deque
inf = float('inf')
mod = 1000000007

def binary(number):
	result = 0
	while number:
		result = result + 1
		number = number & number - 1
	return result

def get_array():
	return list(map(int, sys.stdin.readline().split()))

def get_ints():
	return map(int, sys.stdin.readline().split())
length = int(input())
array = get_array()
day = 0
sum_ = 0
dic = {}
for i in range(length):
	dic.setdefault(array[i], 0)
	dic[array[i]] += 1
	sum_ += array[i]
	page = i + 1
	if page in dic.keys():
		sum_ -= dic[page] * page
		dic[page] = 0
	if sum_ == 0:
		day += 1
print(day)


n = int(input())
a = [int(x) for x in input().split()]
a.insert(0, 0)
i = 1
u = a[i]
c = 0
while i <= n:
	c += 1
	u = max(u, a[i])
	while i <= u:
		u = max(u, a[i])
		i += 1
print(c)


n = int(input())
a = [int(x) for x in input().split()]
i = 0
days = 0
while i < n:
	hi = a[i]
	while hi > i + 1:
		i += 1
		if a[i] > hi:
			hi = a[i]
	days += 1
	i += 1
print(days)


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)


input()
arr = [*map(int, input().split())]
n_days = 0
to_read = -1
for i in range(len(arr)):
	if to_read == -1:
		to_read = arr[i]
	elif arr[i] > to_read:
		to_read = arr[i]
	if i + 1 == to_read:
		n_days += 1
		to_read = -1
print(n_days)


n = int(input())
a = input().split()
for i in range(n):
	a[i] = int(a[i]) - 1
curr_max = 0
total = 0
for curr in range(n):
	curr_max = max(a[curr], curr_max)
	if curr_max == curr:
		total += 1
print(total)


n = int(input())
a = [int(x) for x in input().split()]
days = 0
nex = -1
for (index, ai) in enumerate(a):
	nex = max(nex, ai)
	if nex <= index + 1:
		days += 1
print(days)


from sys import stdin

def ii():
	return int(stdin.readline())

def mi():
	return map(int, stdin.readline().split())

def li():
	return list(mi())
n = ii()
a = li()
x = p = 0
for i in range(n):
	x = max(x, a[i])
	if x == i + 1:
		p += 1
print(p)


import sys
num_pages = int(sys.stdin.readline())
pages = [int(i) for i in sys.stdin.readline().split()]
page_set = set()
count = 0
for (i, page) in enumerate(pages):
	page_set.add(page)
	if i + 1 in page_set:
		page_set.remove(i + 1)
	if len(page_set) == 0:
		count += 1
print(count)


n = int(input().strip())
arr = list(map(int, input().strip().split()))
days = 0
i = 0
while i < n:
	endInd = arr[i] - 1
	while i < endInd:
		i += 1
		endInd = max(endInd, arr[i] - 1)
	days += 1
	i += 1
print(days)


import sys, collections
n = int(sys.stdin.readline())
arr = list(map(int, sys.stdin.readline().split()))
d = 0
p = 0
for i in range(n):
	p = max(p, arr[i])
	if p == i + 1:
		d += 1
		p = 0
print(d)


n = int(input())
arr = [int(i) for i in input().split(' ')]
day_max = 0
counter = 0
for i in range(n):
	if arr[i] > day_max:
		day_max = arr[i]
	if i + 1 == day_max:
		counter += 1
print(counter)


n = int(input(''))
a = input('').split(' ')
for i in range(n):
	a[i] = int(a[i])
day = 0
for p in range(1, n + 1):
	if p >= max(a[:p]):
		day += 1
print(day)


def maxi(z):
	p = a[z]
	while z <= p:
		if a[z] > p:
			p = a[z]
		if z >= p:
			break
		z += 1
	return z
n = int(input())
a = [int(i) - 1 for i in input().split()]
t = 0
d = 0
while t < n:
	t = maxi(t)
	t += 1
	d += 1
print(d)


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


n = int(input())
pages = list(map(int, input().split()))
i = 0
res = 0
while i < len(pages):
	max_input = i + 1
	while max_input > i:
		max_input = max(max_input, pages[i])
		i += 1
	res += 1
print(res)


import sys
n = int(input())
a = [int(c) for c in sys.stdin.readline().split()]
(aktmax, d) = (0, 0)
for (i, c) in enumerate(a, start=1):
	aktmax = max(aktmax, c)
	if aktmax <= i:
		d += 1
print(d)


n = int(input())
A = [int(x) - 1 for x in input().split()]
i = 0
mx = -100000000
days = 0
while i < len(A):
	while True:
		mx = max(mx, A[i])
		i += 1
		if i >= len(A) or mx < i:
			break
	days += 1
print(days)


n = int(input())
arr = list(map(int, input().split(' ')))
c = 0
mx = 0
for i in range(n):
	if arr[i] > mx:
		mx = arr[i]
	if mx == i + 1:
		c += 1
print(c)


n = int(input())
ar = list(map(int, input().split()))
e = 1
cnt = 0
mx = 0
for x in ar:
	mx = max(mx, x)
	if e == x and mx == x:
		cnt += 1
	e += 1
print(cnt)


n = int(input())
a = [int(i) - 1 for i in input().split()]
cnt = 0
idx = 0
mi = 0
while idx < n:
	mi = a[idx]
	while idx < mi:
		idx += 1
		mi = max(mi, a[idx])
	idx += 1
	cnt += 1
print(cnt)


N = int(input())
r = list(map(int, input().split()))
s = 0
i = 0
day = 0
if N == 1:
	print(1)
	exit(0)
while True:
	i += 1
	s = r[i - 1]
	if s > i:
		while max(r[i - 1:s]) > s:
			s = max(r[i - 1:s])
		i = s
	if i >= N:
		break
	day += 1
print(day + 1)


n = int(input())
A = list(map(int, input().split()))
A.insert(0, 0)
C = set()
d = 0
for i in range(1, n + 1):
	C.add(A[i])
	C.discard(i)
	if len(C) == 0:
		d += 1
print(d)


from collections import defaultdict
n = int(input())
a = list(map(int, input().split()))
m = [0 for _ in range(n)]
s = 0
d = 0
for i in range(n):
	m[a[i] - 1] += 1
	s += 1
	if m[i] > 0:
		s -= m[i]
		m[i] = 0
	if s == 0:
		d += 1
print(d)


n = int(input())
a = [int(i) for i in input().split(' ')]
ans = 0
cur_max = 0
for i in range(len(a)):
	cur_max = max(cur_max, a[i])
	if cur_max == i + 1:
		ans += 1
print(ans)


n = int(input())
p = list(map(int, input().split()))
c = 0
cm = 0
for (pos, i) in enumerate(p):
	cm = max(cm, i)
	if cm <= pos + 1:
		c += 1
		cm = 0
print(c)


n = int(input())
arr = [int(x) - 1 for x in input().split()]
i = 0
answer = 0
while i < n:
	answer += 1
	mx = arr[i]
	while i < mx:
		i += 1
		mx = max(mx, arr[i])
	i += 1
print(answer)


def count_days(arr):
	max = 0
	count = 0
	n = len(arr)
	for i in range(n):
		if arr[i] > max:
			max = arr[i]
		if i + 1 == max:
			count += 1
	return count

def read_input(flag=0):
	if flag > 0:
		return int(input())
	return [int(n) for n in input().split()]
n = read_input(1)
print(count_days(read_input()))


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


pages = int(input())
misteries = [0] + list(map(lambda t: int(t), input().split()))
days = 0
now = 1
while now <= pages:
	days += 1
	read_up_to = misteries[now]
	while now < read_up_to:
		now += 1
		if misteries[now] > read_up_to:
			read_up_to = misteries[now]
	now += 1
print(days)


n = int(input())
A = [0] + [int(i) for i in input().split()]
cnt = 0
page = 1
secret = A[1]
days = 0
while page <= n:
	if A[page] > secret:
		secret = A[page]
	while page <= secret:
		if A[page] > secret:
			secret = A[page]
		page += 1
	days += 1
print(days)


n = int(input())
a = list(map(int, input().split()))
z = 0
i = 0
tmp = 0
while i < n:
	z = max(a[i], z)
	if i + 1 == z:
		tmp += 1
	i += 1
print(tmp)


n = int(input())
A = [int(x) for x in input().split()]
mx = 0
d = 0
i = 0
while True:
	if i == len(A):
		break
	d += 1
	mx = A[i]
	while i < mx and i < len(A):
		mx = max(mx, A[i])
		i += 1
print(d)


n = int(input())
a = list(map(int, input().split()))
b = [0 for i in range(0, n)]
h = 0
g = 0
for i in range(0, n):
	if a[i] > g:
		g = a[i]
	if g == i + 1:
		h = h + 1
print(h)


n = int(input())
lst = list(map(int, input().strip().split(' ')))
c = 0
for i in range(n):
	if lst[i] == i + 1 and lst[i] == max(lst[:i + 1]):
		c += 1
print(c)


n = int(input())
a = [int(v) for v in input().split()]
p = 0
c = 0
for j in range(n):
	p = max(p, a[j])
	if p == j + 1:
		c = c + 1
print(c)


n = int(input())
pages = list(map(int, input().split(' ')))
count = 0
readtill = pages[0] - 1
i = 0
while i < n:
	while i <= readtill:
		readtill = max(pages[i] - 1, readtill)
		i += 1
	count += 1
	try:
		readtill = pages[i] - 1
	except IndexError:
		break
print(count)


n = int(input())
a = [int(x) for x in input().split()]
counter = 0
book = set()
for i in range(1, n + 1):
	book.add(a[i - 1])
	book.discard(i)
	if len(book) == 0:
		counter += 1
print(counter)


n = int(input())
line = input().split()
array = [int(x) for x in line]
days = 0
last_page = 0
for i in range(n):
	last_page = max(array[i], last_page)
	if last_page == i + 1:
		days += 1
print(days)


from collections import defaultdict as dd
import math

def nn():
	return int(input())

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

def mi():
	return 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)
	if maxsofar == i + 1 and i < len(l) - 1:
		days += 1
print(days)


x = int(input())
c = 0
m = -1
a = list(map(int, input().split()))
for i in range(x):
	m = max(m, a[i])
	if m == i + 1:
		c += 1
print(c)


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


n = int(input())
a = list(map(int, input().split()))
(ret, mys) = (0, set())
for (i, x) in zip(range(1, n + 1), a):
	mys.add(x)
	if i in mys:
		mys.remove(i)
	if mys.__len__() == 0:
		ret += 1
print(ret)


def main():
	n = int(input())
	a = list(map(int, input().split()))
	temp = a[0]
	cnt = 0
	for i in range(len(a)):
		if temp < a[i]:
			temp = a[i]
		if temp == i + 1:
			cnt += 1
	print(cnt)
	return
main()


R = lambda : map(int, input().split())
n = int(input())
L = list(R())
i = 0
ma = 0
res = 0
while i < n:
	ma = max(ma, L[i])
	if ma == i + 1:
		res += 1
	i += 1
print(res)


def main():
	n = int(input())
	data = [int(v) for v in input().split()]
	i = 0
	r = 0
	vals = set()
	while True:
		if i >= len(data):
			break
		vals.add(data[i])
		if all((v <= i + 1 for v in vals)):
			vals = set()
			r += 1
		i += 1
	print(r)
main()


N = int(input())
m = [int(s) - 1 for s in input().split()]
day = 0
page = -1
while page != N - 1:
	page += 1
	answer = m[page]
	day += 1
	while page != answer:
		new_answer = max(m[page:answer + 1])
		page = answer
		answer = new_answer
print(day)


import sys
from functools import reduce
n = int(input())
arr = list(map(int, sys.stdin.readline().split()))
curr = 0
days = 0
read = []
while curr < n:
	read.append(arr[curr])
	curr_ind = curr + 1
	if curr_ind in read:
		read = [x for x in read if x != curr_ind]
		if not read:
			days += 1
	curr += 1
print(days)


n = int(input())
a = list(map(int, input().split()))
days = 0
i = 0
taina = 0
while True:
	taina = max(a[i], taina)
	if i + 1 == taina:
		days += 1
	i += 1
	if i == n:
		break
print(days)


n = int(input())
a = list(map(int, input().split()))
c = i = j = 0
while i < n:
	f = 0
	k = a[i]
	j = i
	while j < k:
		f = 1
		k = max(a[j], k)
		j += 1
	c += 1
	if f == 0:
		i = j + 1
	else:
		i = j
print(c)


accumulate = __import__('itertools').accumulate
n = int(input())
max_pages = list(accumulate(map(int, input().split(' ')), max))
print(sum((int(max_page == i + 1) for (i, max_page) in enumerate(max_pages))))


n = int(input())
t = [int(x) for x in input().split()]
c = 1
i = 0
x = 0
while t[i] != n:
	x = max(t[i], x)
	i += 1
	if i == x:
		c += 1
print(c)


n = int(input())
days = [int(item) for item in input().split()]
answer = 0
max_day = 0
cur_page = 1
while cur_page <= len(days):
	max_day = max(max_day, days[cur_page - 1])
	while max_day > cur_page and cur_page <= len(days):
		cur_page += 1
		if cur_page <= len(days):
			max_day = max(max_day, days[cur_page - 1])
	cur_page += 1
	answer += 1
print(answer)


def detectiv_cf():
	n = int(input())
	l = [0] + list(map(int, input().split()))
	i = 1
	m = 0
	d = 0
	while i <= n:
		if l[i] > m:
			m = l[i]
		if i == l[i] and i >= m:
			d += 1
		i += 1
	return d
print(detectiv_cf())


n = int(input())
a = input().split(' ')
num = [i for i in range(1, n + 1)]
k = 0
tmp = -1
for i in range(len(a)):
	if tmp == i + 1:
		if i + 1 != int(a[i]) and tmp < int(a[i]):
			tmp = int(a[i])
		else:
			k = k + 1
			tmp = -1
	elif i + 1 != int(a[i]) and tmp < int(a[i]):
		tmp = int(a[i])
	elif i + 1 == int(a[i]) and tmp == -1:
		k = k + 1
print(k)


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


from __future__ import division, print_function
import bisect
import math
import itertools
import sys
from atexit import register
if sys.version_info[0] < 3:
	from io import BytesIO as stream
else:
	from io import StringIO as stream
if sys.version_info[0] < 3:

	class dict(dict):

		def items(self):
			return dict.iteritems(self)

		def keys(self):
			return dict.iterkeys(self)

		def values(self):
			return dict.itervalues(self)
	input = raw_input
	range = xrange
	filter = itertools.ifilter
	map = itertools.imap
	zip = itertools.izip

def sync_with_stdio(sync=True):
	global input, flush
	if sync:
		flush = sys.stdout.flush
	else:
		sys.stdin = stream(sys.stdin.read())
		input = lambda : sys.stdin.readline().rstrip('\r\n')
		sys.stdout = stream()
		register(lambda : sys.__stdout__.write(sys.stdout.getvalue()))

def main():
	n = int(input())
	l1 = list(map(int, input().split()))
	x = 1
	f = 0
	ans = 0
	while x <= n:
		ans += 1
		f = max(f, l1[x - 1])
		while x < f:
			x += 1
			f = max(f, l1[x - 1])
		x += 1
	print(ans)
sync_with_stdio(False)
main()


intin = lambda : map(int, input().split())
Ain = lambda : list(map(int, input().split()))
n = int(input())
a = Ain()
maxi = 0
cnt = 0
for i in range(n):
	maxi = max(maxi, a[i])
	if i + 1 == maxi:
		cnt += 1
print(cnt)


n = int(input())
arr = list(map(int, input().split()))
i = 1
ans = 0
while i <= n:
	j = arr[i - 1]
	k = i
	maxi = j
	while k <= maxi:
		maxi = max(maxi, arr[k - 1])
		k += 1
	ans += 1
	i = maxi + 1
print(ans)


n = int(input())
pg = list(map(int, input().split()))
idx = 0
days = 0
read = 0
until = 0
while idx < len(pg):
	until = max(until, pg[idx])
	while read < until and idx < len(pg):
		until = max(until, pg[idx])
		read += 1
		idx += 1
	days += 1
print(days)


from __future__ import division, print_function
from fractions import Fraction
import sys
import os
from io import BytesIO, IOBase
from itertools import *
import bisect
from heapq import *
from math import *
from copy import *
from collections import deque
from collections import Counter as counter
from itertools import combinations as comb
from itertools import permutations as permutate
from bisect import bisect_left as bl
from bisect import bisect_right as br
from bisect import bisect
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
mod = 1000000007

def inp():
	return sys.stdin.readline().rstrip('\r\n')

def out(var):
	sys.stdout.write(str(var))

def lis():
	return list(map(int, inp().split()))

def stringlis():
	return list(map(str, inp().split()))

def sep():
	return map(int, inp().split())

def strsep():
	return map(str, inp().split())

def zerolist(n):
	return [0] * n

def nextline():
	out('\n')

def testcase(t):
	for p in range(t):
		solve()

def printlist(a):
	for p in range(0, len(a)):
		out(str(a[p]) + ' ')

def lcm(a, b):
	return a * b // gcd(a, b)

def power(a, b):
	ans = 1
	while b > 0:
		if b % 2 == 1:
			ans *= a
		a *= a
		b //= 2
	return ans

def ncr(n, r):
	return factorial(n) // (factorial(r) * factorial(max(n - r, 1)))

def isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	i = 5
	while i * i <= n:
		if n % i == 0 or n % (i + 2) == 0:
			return False
		i = i + 6
	return True

def solve():
	n = int(inp())
	a = lis()
	cnt = 1
	curr = 1
	for i in range(n):
		curr = max(curr, a[i])
		if i + 1 == curr and i != n - 1:
			cnt += 1
			curr = a[i + 1]
	print(cnt)
testcase(1)


n = int(input())
l = list(map(int, input().split()))
m = 0
i = 0
days = 0
while i < n:
	m = max(m, l[i])
	if m > i + 1:
		i += 1
	elif m == l[i]:
		days += 1
		i += 1
print(days)


n = int(input())
A = list(map(int, input().split()))
max_page = -1
count = 0
for i in range(n):
	max_page = max(max_page, A[i])
	if max_page == -1:
		max_page = A[i]
	elif max_page - 1 == i:
		max_page == -1
		count += 1
print(count)


n = int(input())
pages = list(map(lambda x: int(x) - 1, input().split()))
largest = -1
start = 0
ans = 0
while start != len(pages):
	largest = max(pages[start], largest)
	if largest <= start:
		ans += 1
	start += 1
print(ans)


import io
import os
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
kk = lambda : map(int, input().split())
k2 = lambda : map(lambda x: int(x) - 1, input().split())
ll = lambda : list(kk())
(n, ls, d) = (int(input()), kk(), 0)
md = 1
for (i, v) in enumerate(ls):
	if v > md:
		md = v
	if md == i + 1:
		(md, d) = (md + 1, d + 1)
print(d)


n = int(input())
a = map(int, input().split())
cur = 0
res = 0
for (i, v) in enumerate(a):
	cur = max(cur, v)
	if cur == i + 1:
		res += 1
print(res)


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


import sys
import copy
input = sys.stdin.readline
N = int(input())
a = [int(x) - 1 for x in input().split()]
i = -1
page = 0
cnt = 0
while i < N:
	i += 1
	if i == N:
		break
	cnt += 1
	page = max(a[i], page)
	while i < page:
		i += 1
		page = max(a[i], page)
print(cnt)


n = int(input())
a = list(map(int, input().split()))
(cnt, i) = (0, 0)
tmp = 0
while i < n:
	cnt += 1
	tmp = a[i]
	while i < n and i + 1 <= tmp:
		tmp = max(tmp, a[i])
		i += 1
print(cnt)


import sys
line1 = sys.stdin.readline()
line2 = sys.stdin.readline()
n = int(line1)
arr = list(map(lambda x: int(x), line2.split()))
m = 0
t = 0
for x in range(len(arr)):
	temp = arr[x]
	if temp > t:
		t = temp
	if t == x + 1:
		m += 1
print(m)


n = int(input())
x = [int(y) for y in input().split()]
days = 0
mx = 0
for i in range(n):
	mx = max(mx, x[i])
	if mx == i + 1:
		days += 1
print(days)


n = int(input())
A = [int(x) for x in input().split()]
result = 0
i = 0
while i < n:
	h = A[i] - 1
	while i < n and i <= h:
		h = max([h, A[i] - 1])
		i += 1
	result += 1
print(result)


n = int(input())
l = list(map(int, input().split()))
l.insert(0, 0)
m = l[1]
c = 0
for i in range(1, n + 1):
	if l[i] > m:
		m = l[i]
	if i == m:
		c += 1
print(c)


class CodeforcesTask1140ASolution:

	def __init__(self):
		self.result = ''
		self.pages = 0
		self.mysteries = []

	def read_input(self):
		self.pages = int(input())
		self.mysteries = [int(x) for x in input().split(' ')]

	def process_task(self):
		days = 0
		page = 1
		mystery = self.mysteries[0]
		while page <= self.pages:
			if self.mysteries[page - 1] > mystery:
				mystery = self.mysteries[page - 1]
			if mystery == page:
				days += 1
			page += 1
		self.result = str(days)

	def get_result(self):
		return self.result
Solution = CodeforcesTask1140ASolution()
Solution.read_input()
Solution.process_task()
print(Solution.get_result())


import re, math, decimal, bisect

def read():
	return input().strip()

def iread():
	return int(input().strip())

def viread():
	return [int(_) for _ in input().strip().split()]
n = iread()
pages = viread()
days = 0
i = 0
while i < len(pages):
	days += 1
	goto = pages[i] - 1
	while i < goto:
		i += 1
		if i >= len(pages):
			break
		goto = max(pages[i] - 1, goto)
	i += 1
print(days)


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:
		days += 1
print(days)


n = int(input())
arr = list(map(int, input().strip().split()))
pages = 1
i = 1
while i != n:
	if arr[i - 1] == i:
		maximum = max(arr[0:arr[i - 1]])
		if maximum <= i:
			pages += 1
	i = i + 1
print(pages)


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


n = int(input())
l = list(map(int, input().split()))
mx = -1
cou = 0
ll = [0] * 10001
mx = -1
for i in range(n):
	if i + 1 == l[i] and l[i] > mx:
		cou += 1
	if mx < l[i]:
		mx = l[i] - 1
print(cou)


n = int(input())
a = [int(o) for o in input().split()]
ma = 0
i = 0
d = 0
while i < n:
	ma = a[i] - 1
	while i <= ma:
		if a[i] - 1 > ma:
			ma = a[i] - 1
		i += 1
	d += 1
print(d)


import sys

class ADetectiveBook:

	def solve(self):
		n = int(input())
		a = [int(_) - 1 for _ in input().split()]
		done = [0] * n
		ans = 0
		i = 0
		while i < n:
			k = i
			r = a[k]
			while k < n and k <= r:
				r = max(r, a[k])
				k += 1
			i = k
			ans += 1
		print(ans)
solver = ADetectiveBook()
input = sys.stdin.readline
solver.solve()


k = []
z = count = f = 0
n = int(input(''))
b = input('')
l = b.split()
k = list(map(int, l))
for q in range(n):
	z = k[:q + 1]
	f = max(z)
	if f <= q + 1:
		count += 1
print(count)


import sys

def main():
	(n, q) = (int(sys.stdin.readline().strip()), [int(i) for i in sys.stdin.readline().strip().split()])
	s = -1
	a = 0
	for i in range(n):
		s = max(q[i], i + 1, s)
		if s == i + 1:
			a += 1
	print(a)
main()


import math
import sys
import bisect
input = sys.stdin.readline
t = 1
for _ in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	i = 1
	ans = 0
	l.insert(0, 0)
	while i <= n:
		j = i
		maxi = l[i]
		while j <= maxi:
			maxi = max(maxi, l[j])
			j += 1
			i += 1
		ans += 1
	print(ans)


n = int(input())
l1 = [int(x) for x in input().split()]
table = []
j = 1
days = 0
for i in range(n):
	table.append(l1[i])
	if j == max(table):
		days += 1
	j += 1
print(days)


n = int(input())
l = [int(i) for i in input().split()]
ct = 0
ind = 0
proxm = 0
while ind < len(l):
	proxm = max(l[ind] - 1, proxm)
	if ind == proxm:
		ct += 1
	ind += 1
print(ct)
proxm


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())
li = list(map(int, input().split()))
count = 0
ma = li[0]
for i in range(n):
	ma = max(ma, li[i])
	if i + 1 == ma:
		count += 1
print(count)


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


n = int(input())
l = list(map(int, input().split()))
c = 0
l.sort()
for i in range(n):
	if i + 1 == l[i]:
		c += 1
print(c)


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


n = int(input())
a = [int(i) for i in input().split()]
kol = [0 for i in range(len(a) + 1)]
a.insert(0, 0)
k = 0
res = 0
for i in range(1, len(a)):
	kol[a[i]] += 1
	k += 1
	k -= kol[i]
	kol[i] = 0
	if k == 0:
		res += 1
print(res)


(n, li, ans) = (int(input()), list(map(int, input().split())), 0)
a = list(sorted(li))
for i in range(len(a)):
	if a[i] == i + 1:
		ans += 1
print(ans)


n = int(input())
a = list(map(int, input().split()))
rez = 0
maxx = 0
for i in range(1, n + 1):
	if a[i - 1] > maxx:
		maxx = a[i - 1]
	if maxx == i:
		rez += 1
		maxx = 0
print(rez)


import sys

def main():
	n = int(sys.stdin.readline().strip())
	nums = list(map(int, sys.stdin.readline().strip().split()))
	days = 0
	cur = 0
	while cur < n:
		day_max = nums[cur]
		while cur + 1 != day_max and cur < n - 1:
			cur += 1
			day_max = max(day_max, nums[cur])
		days += 1
		cur += 1
	print(days)
main()


n = int(input())
a = [int(x) for x in input().split()]
m = 0
t = 0
for (i, x) in enumerate(a):
	if x > m:
		m = x
	if i + 1 == x and x == m:
		t += 1
print(t)


n = int(input().lstrip())
nums = list(map(int, input().lstrip().split()))
from collections import deque
res = 0
dq = deque()
for (i, num) in enumerate(nums):
	dq.append(num - 1)
	while dq and dq[0] <= i:
		dq.popleft()
	if not dq:
		res += 1
print(res)


x = int(input())
t = list(map(int, input().split()))
t1 = 0
z = 1
for i in range(x):
	z = max(z, t[i])
	if i + 1 >= z:
		if i < x - 1:
			z = max(z, t[i + 1])
		t1 = t1 + 1
print(t1)


n = int(input())
pages = [int(x) for x in input().split()]
days = 0
lastPage = 0
maxMisteryPage = 0
for i in range(1, n + 1):
	pageNeededToRead = pages[i - 1]
	if maxMisteryPage > pageNeededToRead:
		pageNeededToRead = maxMisteryPage
	else:
		maxMisteryPage = pageNeededToRead
	if pageNeededToRead == i:
		days += 1
print(days)


n = int(input())
a = map(int, input().split())
i = 1
mp = 0
d = 0
while i <= n:
	mp = max(mp, a.__next__())
	if i == mp:
		d += 1
		mp = 0
	i += 1
print(d)