def sieve(n)
  primes = Array.new
  primes[0] = 0
  primes[1] = 0
  2.upto(n-1) do |i|
    primes[i] = i;
  end

  i = 2;
  while i*i < n
    if primes[i] != 0
      (i*i).step(n, i) do |j|
        primes[j] = 0
      end
    end
    i = i + 1
  end
  primes
end

primes = sieve(10000)
loop do
  cnt = 0
  data = gets
  if data == nil then break end
  n = data.to_i
  2.upto(n) do |i|
    if primes[i] != 0 && primes[n+1-i] != 0
      cnt = cnt + 1
    end
  end
  puts cnt
end