#include <bits/stdc++.h>
using namespace std;
const int Maxn = 1e6;
int prim[Maxn], top;
bool flag[Maxn];
void getPrim() {
  for (int i = 2; i < Maxn; ++i) {
    if (!flag[i]) prim[top++] = i;
    for (int j = 0; j < top && i * prim[j] < Maxn; ++j) {
      flag[i * prim[j]] = 1;
      if (i % prim[j] == 0) break;
    }
  }
}
int rev(int x) {
  int ret = 0;
  while (x) {
    ret *= 10;
    ret += x % 10;
    x /= 10;
  }
  return ret;
}
int main() {
  int d;
  getPrim();
  cin >> d;
  int num = 0;
  for (int i = 0; i < top; ++i) {
    int re = rev(prim[i]);
    if (re != prim[i] && !flag[re]) num++;
    if (num == d) {
      cout << prim[i] << endl;
      break;
    }
  }
  return 0;
}

### Prompt

In cpp, your task is to solve 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 Maxn = 1e6;
int prim[Maxn], top;
bool flag[Maxn];
void getPrim() {
  for (int i = 2; i < Maxn; ++i) {
    if (!flag[i]) prim[top++] = i;
    for (int j = 0; j < top && i * prim[j] < Maxn; ++j) {
      flag[i * prim[j]] = 1;
      if (i % prim[j] == 0) break;
    }
  }
}
int rev(int x) {
  int ret = 0;
  while (x) {
    ret *= 10;
    ret += x % 10;
    x /= 10;
  }
  return ret;
}
int main() {
  int d;
  getPrim();
  cin >> d;
  int num = 0;
  for (int i = 0; i < top; ++i) {
    int re = rev(prim[i]);
    if (re != prim[i] && !flag[re]) num++;
    if (num == d) {
      cout << prim[i] << endl;
      break;
    }
  }
  return 0;
}

```