#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
bool a[10001];
int main() {
	fill(a, a + 10001, true);
	a[0] = false; a[1] = false;
	for (int i = 2; i <= 10000; i++) {
		if (a[i]) {
			int j = 2;
			while (i*j <= 10000) {
				a[i*j] = false;
				j++;
			}
		}
	}
	int n;
	while (cin >> n) {
		int p = 0;
		for (int i = 1; i <= n; i++) {
			if (a[i] && a[n + 1 - i]) {
				p++;
			}
		}
		cout << p << endl;
	}
}