import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
class Solution {
static int N;
static int max;
public static void main(String args[]) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st;
N = Integer.parseInt(br.readLine());
int[] arr = new int[501];
int[] dp = new int[501];
if(N == 1) {
System.out.print(0);
return ;
}
max =0 ;
for (int i = 0; i < N; i++) {
st = new StringTokenizer(br.readLine());
int start = Integer.parseInt(st.nextToken());
int end = Integer.parseInt(st.nextToken());
arr[start] = end;
max = max > start ? max : start;
}
LIS(arr , dp);
int maxDp = 0;
for (int i = 1 ; i <= max ; i++) {
maxDp = maxDp > dp[i] ? maxDp : dp[i];
}
System.out.println(max - (max-N) - maxDp);
}
static void LIS(int[] arr , int[] dp) {
int maxIndex;
int maxValue;
for (int i = 1; i <= max; i++) {
if (arr[i] == arr[i - 1]) {
dp[i] = dp[i - 1];
}else if(arr[i] == 0){
continue;
}else {
maxIndex = -1;
maxValue = 1;
for (int j = i - 1; j >= 0; j--) {
if (arr[j] < arr[i] && maxValue <= dp[j]) {
maxValue = dp[j];
maxIndex = j;
}
}
dp[i] = maxIndex == -1 ? 1 : dp[maxIndex] + 1;
}
}
}
}