import sys from sys import stdin import bisect N = int(stdin.readline()) A = list(map(int,stdin.readline().split())) nums = [] inds = {} for i in range(N): if A[i] not in inds: nums.append(A[i]) inds[A[i]] = [] inds[A[i]].append(i) nums.sort() ind = 0 ans = 0 for v in nums: inds[v].sort() nex = ( bisect.bisect_left(inds[v],ind) ) % len(inds[v]) for j in range(len(inds[v])): nexind = inds[v][(nex+j) % len(inds[v])] if nexind < ind: ans += 1 ind = nexind print (ans)