#include <bits/stdc++.h>
using namespace std;
const int maxN = 1100000;
int prime[maxN / 4];
bool vst[maxN];
int tot_prime = 0;
void init() {
  memset(vst, 0, sizeof(vst));
  prime[tot_prime++] = 2;
  for (int i = 3, j; i < maxN; i += 2)
    if (!vst[i]) {
      prime[tot_prime++] = i;
      for (j = i + i; j < maxN; j += i) vst[j] = 1;
    }
}
const int maxM = 11185;
int ans[maxM];
int na = 0;
int cc(int N) {
  int ret = 0;
  do {
    ret = ret * 10 + N % 10;
    N /= 10;
  } while (N);
  return ret;
}
bool bs(int key) {
  if (key % 2 == 0) return 0;
  if (key > prime[tot_prime - 1]) {
    for (int i = 0; i < tot_prime && prime[i] <= (key / prime[i]); ++i)
      if (key % prime[i] == 0) return 0;
    return 1;
  }
  int l = 0, r = tot_prime - 1, m;
  while (l <= r) {
    m = (l + r) >> 1;
    if (prime[m] == key) return 1;
    if (prime[m] > key)
      r = m - 1;
    else
      l = m + 1;
  }
  return 0;
}
void f() {
  na = 0;
  int d;
  for (int i = 0; i < tot_prime && na < maxM; ++i) {
    d = cc(prime[i]);
    if (d != prime[i] && bs(d)) {
      ans[na++] = prime[i];
    }
  }
}
int main() {
  init();
  f();
  int N;
  scanf("%d", &N);
  printf("%d\n", ans[N - 1]);
  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;
const int maxN = 1100000;
int prime[maxN / 4];
bool vst[maxN];
int tot_prime = 0;
void init() {
  memset(vst, 0, sizeof(vst));
  prime[tot_prime++] = 2;
  for (int i = 3, j; i < maxN; i += 2)
    if (!vst[i]) {
      prime[tot_prime++] = i;
      for (j = i + i; j < maxN; j += i) vst[j] = 1;
    }
}
const int maxM = 11185;
int ans[maxM];
int na = 0;
int cc(int N) {
  int ret = 0;
  do {
    ret = ret * 10 + N % 10;
    N /= 10;
  } while (N);
  return ret;
}
bool bs(int key) {
  if (key % 2 == 0) return 0;
  if (key > prime[tot_prime - 1]) {
    for (int i = 0; i < tot_prime && prime[i] <= (key / prime[i]); ++i)
      if (key % prime[i] == 0) return 0;
    return 1;
  }
  int l = 0, r = tot_prime - 1, m;
  while (l <= r) {
    m = (l + r) >> 1;
    if (prime[m] == key) return 1;
    if (prime[m] > key)
      r = m - 1;
    else
      l = m + 1;
  }
  return 0;
}
void f() {
  na = 0;
  int d;
  for (int i = 0; i < tot_prime && na < maxM; ++i) {
    d = cc(prime[i]);
    if (d != prime[i] && bs(d)) {
      ans[na++] = prime[i];
    }
  }
}
int main() {
  init();
  f();
  int N;
  scanf("%d", &N);
  printf("%d\n", ans[N - 1]);
  return 0;
}

```