#include <iostream>
#define LEN 10001

using namespace std;

int main(void){
	int N;
    int count;
    bool prime[LEN] = {0};
    prime[0] = 1;
    prime[1] = 1;
    for(int i = 2; i*i < LEN; i++){
        for(int j = i*2; j < LEN; j += i){
            prime[j] = 1;
        }
    }
    while(cin >> N){
        count = 0;
        for(int i = 1; i <= N; i++){
            if((!prime[i]) && (!prime[N-i+1])) count++;
        }
        cout << count << endl;
	}
	return 0;
}