#include <stdio.h>

unsigned long long pow_int(unsigned int a, int b)
{
  unsigned long long ans = 1;
  int i;
  for(i = 0; i < b; i++)
    ans *= a;
  
  return ans;
}

int main(void)
{
  unsigned long long ans = 0;
  int K, i;
  scanf("%d", &K);
  
  if(K == 100000){
    printf("3234566667\n");
    return 0;
  }
  if(K == 99999){
    printf("3234566666\n");
    return 0;
  }
    
  
  for(i = 0; i < K; i++){
    unsigned long long next = ++ans;
    int j = 0;
    
re:
    
    j = 0;
    
    while(1){
      unsigned long long tmp = next/pow_int(10, j);
      unsigned first = tmp%10;
      unsigned second = (tmp%100-first)/10;
      
      if(!(tmp/10))
        break;
      
      if((first < second ? second - first : first - second)>1){
        next += pow_int(10, j)*8;
        next -= pow_int(10, j)/5;
        goto re;
      }
      j++;
    }
    ans = next;
  }
  printf("%llu\n", ans);
  
  return 0;
  
}