ps = [2, 3]

readlines.each do |l|
  n = l.to_i
  if ps.max < n
    ps.max.upto(n) do |x|
      ps.each do |y|
        break if x % y == 0
        if Math.sqrt(x) < y
          ps.push(x)
          break
        end
      end
    end
  end

  a = (1..n).to_a
  ra = a.reverse
  count = 0
  0.upto(n-1) do |i|
    count += 1 if ps.include?(a[i]) && ps.include?(ra[i])
  end

  puts count
end