#include <stdio.h>
#define min(x, y) ((x)>(y) ? (y) : (x))
#define max(x, y) ((x)<(y) ? (y) : (x))
#define swap(type, x, y) do{ type t = x; x = y; y = t; }while(0)

void quick(long array[], int left, int right);

long lunlun[265726] = {0};

void dfs(long num, int len){
  if(len > 10)  return;
  lunlun[++lunlun[0]] = num;
  for(long i=-1; i<=1; i++)
    if(num%10+i>=0 && num%10+i<=9){
      long newnum = num*10 + num%10+i;
      dfs(newnum, len+1);
    }
  
  return;
}

int main(){
  int k;  scanf("%d", &k);

  for(long i=1; i<=9; i++)
    dfs(i, 1);

  quick(lunlun, 1, lunlun[0]);

  printf("%ld\n", lunlun[k]);
  return 0;
}

void quick(long array[], int left, int right){
  int pl = left, pr = right;
  long x = array[(left+right) / 2];
  do{
    while(array[pl] < x)  pl++;
    while(array[pr] > x)  pr--;
    if(pl <= pr){
      swap(long, array[pl], array[pr]);
      pl++, pr--;
    }
  }while(pl <= pr);
  if(pl < right)  quick(array, pl, right);
  if(pr > left)   quick(array, left, pr);
}
  
