
object Main extends App {
	val N = scala.io.StdIn.readInt
	val A = scala.io.StdIn.readLine.split(" ").map(_.toLong).sorted

	var answer = 0
	var temp = 0L
	var flag = 0L

	for(i<- A){
		if(temp != i){
			if(flag > 0) answer = answer + (temp - flag).toInt
			temp = i
			flag = i - 1L
		}else{
			if(flag <= 0) answer = answer + 1
			else flag = flag - 1
		}

	}

	if(flag > 0){
		println(answer + (temp - flag).toInt)
	}else{
		println(answer)
	}

	
}
