require 'prime'

def main
  while n = gets
    n = n.chomp.to_i
    puts solve(n)
  end
end

def solve n
  res = 0
  (1..n).each do |i|
    o = n - i + 1
    res += 1 if Prime.prime? i and Prime.prime? o
  end
  res
end

main