#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <fstream>
#include <complex>
#include <stack>
#include <queue>

using namespace std;
typedef long long LL;
typedef pair<int, int> P;
static const double EPS = 1e-5;

#define FOR(i,k,n) for (int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n)
const int MAX = 10000;
int main(void){
  int N;
  bool isPrime[10001];
  FOR(i,2,10001) isPrime[i]=true;
  for(int i=2; i<=10000; i++){
    if(isPrime[i]){
      for(int k=2; i*k<=10000; k++){
        isPrime[i*k]=false;
      }
    }
  }
  while(cin>>N){
    int count=0;
    for(int i=2; i<N; i++){
      if(isPrime[i]&&isPrime[N+1-i]){
        count++;
      }
    }
    cout<<count<<endl;
  }
  return 0;
}