#include <iostream>
#include <vector>
using namespace std;
int main( void )
{
	// prime numbers table
	vector <bool> isPrime( 10001, false );
	isPrime[2] = true;
	for ( int i = 3; i < 10001; i += 2 )
	{
		isPrime[i] = true;
	}

	for ( int i = 3; i < 10001; i += 2 )
	{
		for ( int j = i + i; j <= 10001; j += i )
		{
			isPrime[j] = false;
		}
	}

	
	int N;
	while ( cin >> N )
	{
		int kotae = 0;
		int i, j;
		for ( i = 1, j = N; i <= N && j >= 1; i++, j-- )
		{
			if ( isPrime[i] && isPrime[j] )
				kotae++;
		}
		cout << kotae << endl;
	}

	return 0;
}