#include <bits/stdc++.h>
using namespace std;
const int INF = 1 << 30;
const int maxn = 1000007;
int k;
bool check[maxn];
int p[maxn], tot, q[maxn], top;
void Eurl() {
  for (int i = 2; i <= maxn; i++) {
    if (!check[i]) p[++tot] = i;
    for (int j = 1; j <= tot; j++) {
      if (i * p[j] > maxn) break;
      check[i * p[j]] = 1;
      if (i % p[j] == 0) break;
    }
  }
}
bool find(int key, int h[], int l, int r) {
  int mid;
  while (l <= r) {
    mid = (l + r) >> 1;
    if (h[mid] == key) return 1;
    if (key < h[mid])
      r = mid - 1;
    else
      l = mid + 1;
  }
  return 0;
}
void work() {
  int c, b;
  scanf("%d", &k);
  for (int i = 1; i <= tot; i++) {
    c = 0;
    b = p[i];
    while (b) {
      c = c * 10 + (b % 10);
      b /= 10;
    }
    if (c != p[i] && find(c, p, 1, tot)) {
      top++;
    }
    if (top == k) {
      printf("%d\n", p[i]);
      break;
    }
  }
}
int main() {
  Eurl();
  work();
  return 0;
}

### Prompt

Please formulate 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;
const int INF = 1 << 30;
const int maxn = 1000007;
int k;
bool check[maxn];
int p[maxn], tot, q[maxn], top;
void Eurl() {
  for (int i = 2; i <= maxn; i++) {
    if (!check[i]) p[++tot] = i;
    for (int j = 1; j <= tot; j++) {
      if (i * p[j] > maxn) break;
      check[i * p[j]] = 1;
      if (i % p[j] == 0) break;
    }
  }
}
bool find(int key, int h[], int l, int r) {
  int mid;
  while (l <= r) {
    mid = (l + r) >> 1;
    if (h[mid] == key) return 1;
    if (key < h[mid])
      r = mid - 1;
    else
      l = mid + 1;
  }
  return 0;
}
void work() {
  int c, b;
  scanf("%d", &k);
  for (int i = 1; i <= tot; i++) {
    c = 0;
    b = p[i];
    while (b) {
      c = c * 10 + (b % 10);
      b /= 10;
    }
    if (c != p[i] && find(c, p, 1, tot)) {
      top++;
    }
    if (top == k) {
      printf("%d\n", p[i]);
      break;
    }
  }
}
int main() {
  Eurl();
  work();
  return 0;
}

```