#include <bits/stdc++.h>
using namespace std;
int i, n, j, prime[1000005], k, a;
int reverse(int i) {
  int ret = 0;
  while (i) {
    ret = ret * 10 + i % 10;
    i /= 10;
  }
  return ret;
}
int main() {
  scanf("%d", &n);
  for (i = 2; i <= 1000000; i++)
    if (!prime[i])
      for (j = i + i; j <= 1000000; j += i) prime[j] = true;
  for (i = 2; i <= 1000000; i++) {
    k = reverse(i);
    if (!prime[k] && !prime[i] && reverse(i) != i) {
      --n;
    }
    if (!n) {
      printf("%d\n", i);
      return 0;
    }
  }
}

### Prompt

Your challenge is to write a CPP solution to the following problem:

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 i, n, j, prime[1000005], k, a;
int reverse(int i) {
  int ret = 0;
  while (i) {
    ret = ret * 10 + i % 10;
    i /= 10;
  }
  return ret;
}
int main() {
  scanf("%d", &n);
  for (i = 2; i <= 1000000; i++)
    if (!prime[i])
      for (j = i + i; j <= 1000000; j += i) prime[j] = true;
  for (i = 2; i <= 1000000; i++) {
    k = reverse(i);
    if (!prime[k] && !prime[i] && reverse(i) != i) {
      --n;
    }
    if (!n) {
      printf("%d\n", i);
      return 0;
    }
  }
}

```