def is_prime(x)
  for i in (2...x)
    return false if x % i == 0
    return true if i * i > x
  end
end

$isp = Array.new(2, false)
for i in (2..10000)
  $isp.push(is_prime(i))
end

def count(n)
  ans = 0
  (1..n).each do |i|
    ans += 1 if $isp[i] and $isp[n + 1 - i]
  end
  ans
end

while line = gets
  puts count(line.to_i)
end