#include <bits/stdc++.h>
using namespace std;
int sum(int n) {
  int ans = 0;
  while (n) {
    ans += n % 10;
    n /= 10;
  }
  return ans;
}
bool Prime(int n) {
  for (int i = 2; i <= sqrt(n); i++) {
    if (n % i == 0) return false;
  }
  return true;
}
bool judge(int n) {
  int digit[5], tb = 0;
  int tmp = n;
  int prime[15], tx = 0;
  for (int i = 2; i <= sqrt(n); i++) {
    while (tmp % i == 0) {
      prime[tx++] = i;
      tmp /= i;
    }
  }
  if (tmp != 1) prime[tx++] = tmp;
  int sum1 = 0, sum2 = 0;
  sum1 = sum(n);
  for (int i = 0; i < tx; i++) {
    int m = sum(prime[i]);
    sum2 += m;
  }
  if (sum1 == sum2) return true;
  return false;
}
int main() {
  int num[1005], tb = 0;
  for (int i = 4; i < 10003; i++) {
    if (judge(i) && !Prime(i)) {
      num[tb++] = i;
    }
  }
  int n;
  while (cin >> n) {
    cout << num[n - 1] << endl;
  }
  return 0;
}
