macho = gets.to_i.times.map{gets.split.map &:to_i}
dp = Array.new(macho.size+1){Array.new(100001,9999)}
dp[0][0] = 0
(1..macho.size).each{|i|
  dp[i][macho[i-1][0]] = dp[i-1].min+1
  (0..100000-macho[i-1][1]).each{|j| dp[i][j] = [dp[i][j],dp[i-1][j+macho[i-1][1]]].min}
}
p dp[macho.size].min