### constant

MAX_P = 10000

### subroutines

def gen_primes(max_p)
  primes = Array.new(max_p + 1){true}
  primes[0] = primes[1] = false

  s_max_p = Math.sqrt(max_p + 0.5).to_i

  for p in (2..s_max_p)
    if primes[p]
      for q in (p * p).step(max_p, p)
        primes[q] = false
      end
    end
  end

  primes
end

### main

primes = gen_primes(MAX_P)

while line = gets
  n = line.strip.to_i

  count = 0

  for i in (1..n)
    if primes[i] && primes[n + 1 - i]
      count += 1
    end
  end

  puts count
end