class PP

  N = 10000

  def initialize
    @ary = Array.new(N+1){-1}
    @ary[0] = @ary[1] = 0
    (2..N).each{|i|
      @ary[i] = prime(i)? 1 : 0
      (2..(N/i)).each{|j|
        @ary[i*j] = 0
      }
    }
  end

  def main
    while true
      l = gets
      break if l.nil?
      n = l.chomp.to_i
      ans = 0
      (1..n).each{|i|
        j = n-i+1
        ans += 1 if @ary[i] == 1 && @ary[j] == 1
      }
      puts ans
    end
  end

  :private
  def prime(i)
    (2..Math.sqrt(i.to_f).to_i).each{|j|
      if @ary[j] == 1
        if i%j == 0
          return false
        end
      end
    }
    return true
  end
end

def main
  pp = PP.new
  pp.main
end

main