#import <stdio.h>
#import <Foundation/Foundation.h>

NSInteger solve(NSInteger K) {
  if (K < 10) {
    return K;
  }
  NSMutableArray *queue = [[NSMutableArray alloc] init];
  int i = 0;
  for(i=1; i<10; i++) {
    [queue addObject: [NSNumber numberWithInteger: i]];
  }
  NSInteger count = 9;
  NSInteger result = -1;
  while (count < K) {
    NSInteger top = [((NSNumber *)[queue objectAtIndex: 0]) integerValue];
    [queue removeObjectAtIndex: 0];
    
    NSInteger last = top % 10;
    NSInteger start;
    for(start=last-1; start<=last+1; start++) {
      if (start < 0 || start > 9) {
        continue;
      }
      NSInteger next = top * 10 + start;
      [queue addObject: [NSNumber numberWithInteger: next]];
      count ++;
      if(count == K) {
        result = next;
        break;
      }
    }
  }
  return result;
}

int main(int argc, char **argv) {
  NSInteger K;
  scanf("%ld", &K);
  printf("%ld", solve(K));
}