require 'prime'

def solve n
  count = 0
  (n+1).times do |i|
    if Prime.prime?(i) && Prime.prime?(n + 1 - i)
      count += 1
    end
  end
  count
end


while input = $stdin.gets
  n = input.to_i
  p solve(n)
end