require 'prime'

readlines.each do |l|
  n = l.to_i
  indexes = []
  (1..n).to_a.each_with_index do |x, i|
    indexes.push(i+1) if x.prime?
  end

  count = 0
  indexes.each do |x|
    count += 1 if indexes.include?((n+1)-x)
  end

  puts count
end