#include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <cmath>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <iostream>
#include <climits>
#include <cfloat>

using namespace std;


int main()
{
	bool isPrime[10000 + 1];
	fill(isPrime, isPrime+10000+1, true);
	isPrime[0] = isPrime[1] = false;
	for (int i = 2; i <= 10000; ++i)
	{
		if (isPrime[i])
		{
			for (int j = i*2; j <= 10000; j += i)
				isPrime[j] = false;
		}
	}

	int N;
	while (scanf("%d", &N) != EOF)
	{
		int ans = 0;
		for (int i = 0; i <= N; ++i)
			if (isPrime[i] && isPrime[N+1-i])
				++ans;
		printf("%d\n", ans);
	}

	return 0;
}