#include <bits/stdc++.h>
using namespace std;
int prime(int k) {
  for (int i = 2; i * i <= k; i++)
    if (k % i == 0) return 0;
  return 1;
}
int f(int k) {
  int l;
  while (k) {
    l = 10 * l + k % 10;
    k /= 10;
  }
  return l;
}
int n, i;
int main() {
  cin >> n;
  for (i = 13; n > 0; n -= (i != f(i)) ? (prime(i) + prime(f(i))) / 2 : 0, i++)
    ;
  cout << --i;
  return 0;
}

### Prompt

Construct a CPP code solution to the problem outlined:

qd ucyhf yi q fhycu dkcruh mxeiu huluhiu yi q tyvvuhudj fhycu dkcruh. oekh jqia yi je vydt jxu djx ucyhf.

Input

jxu ydfkj sediyiji ev q iydwbu ydjuwuh d (1 ≤ d ≤ 11184) — jxu edu-rqiut ydtun ev jxu ucyhf je vydt.

Output

ekjfkj q iydwbu dkcruh.

Examples

Input

1


Output

13

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int prime(int k) {
  for (int i = 2; i * i <= k; i++)
    if (k % i == 0) return 0;
  return 1;
}
int f(int k) {
  int l;
  while (k) {
    l = 10 * l + k % 10;
    k /= 10;
  }
  return l;
}
int n, i;
int main() {
  cin >> n;
  for (i = 13; n > 0; n -= (i != f(i)) ? (prime(i) + prime(f(i))) / 2 : 0, i++)
    ;
  cout << --i;
  return 0;
}

```