var n;
var x = [];
var stn;
var st = [];

function st_init(n){
	stn = 1;
	while(stn < n){
		stn *= 2;
	}
	rep(stn * 2 - 1, function(i){
		st[i] = [-1, false];
	});
}

function st_get(i, l, r, k){
	if(i < l || r <= i){
		return [-1, false];
	}
	if(i === l && r === i + 1){
		return st[k];
	}
	var m = (l + r) >> 1;
	var p = st_get(i, l, m, 2 * k + 1);
	var q = st_get(i, m, r, 2 * k + 2);
	return p[0] > q[0] ? p : q; 
}

function st_set(a, b, x, l, r, k){
	if(b <= l || r <= a){
		return;
	}
	if(a <= l && r <= b){
		st[k] = x;
		return;
	}
	var m = (l + r) >> 1;
	st_set(a, b, x, l, m, 2 * k + 1);
	st_set(a, b, x, m, r, 2 * k + 2);
}

function main(){
	n = scan();
	rep(n, function(i){
		x[i] = scan();
	});

	var y = [].concat(x).sort(function(a, b){
		return a - b;
	});
	var p = 0;
	var t = 0;
	var z = {};
	rep(n, function(i){
		if(p !== y[i]){
			z[y[i]] = t++;
			p = y[i];
		}
	});
	rep(n, function(i){
		x[i] = z[x[i]];
	});

	st_init(t);

	var ans = 0;
	var s = -1;
	rep(n, function(i){
		if(!st_get(x[i], 0, stn, 0)[1]){
			++ans;
		}

		st_set(x[i], x[i] + 1, [i, true], 0, stn, 0);

		if(s > x[i]){
			st_set(x[i] + 1, s + 1, [i, false], 0, stn, 0);
		}
		else{
			s = x[i];
		}
	});
	print(ans);
}
 
function rep(a, b, c){
	if(c === undefined){
		c = b;
		b = a;
		a = 0;
	}
	for(var i = a; i < b; ++i){
		if(c(i) === false){
			break;
		}
	}
}
 
process.stdin.resume();
process.stdin.setEncoding('utf8');
 
var input = '';
var input_index = 0;
 
function scan(type){
	if(type === 'string'){
		return input[input_index++];
	}
	else{
		return +input[input_index++];
	}
}
 
function print(val){
	console.log(val);
}
 
process.stdin.on('data', function(chunk){
	input += chunk;
});
process.stdin.on('end', function(){
	input = input.split(/\s+/);
	main();
});