#include<stdio.h>
#include<string.h>

int main(){
	char so[10001];
	int i,j,n;
	memset(so,0,sizeof(so));
	
	so[0]=so[1]=1;
	for(i=2;i<=100;i++){
		for(j=2*i;j<=10000;j+=i){
			so[j]=1;
		}
	}
	
	while(~scanf("%d",&n)){
		j=0;
		for(i=1;i<=n;i++){
			if(so[i]==0 && so[n+1-i]==0)++j;
		}
		printf("%d\n",j);
	}
	
	
	return 0;
}