import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayDeque;
import java.util.Arrays;
import java.util.NoSuchElementException;

public class Main implements Runnable{

	public static void main(String[] args) {
		new Thread(null,new Main(), "" ,Runtime.getRuntime().maxMemory()).start();
	}
	
	long pow(long a,long n) {
		long r=1;
		for(;n>0;n>>=1,a=a*a)if(n%2==1)r*=a;
		return r;
	}
	
	long gcd(long a,long b) {
		return a==0?b:gcd(b%a,a);
	}
	
	long get(int len,int top) {
		long[][] dp=new long[len][10];
		dp[len-1][top]=1;
		for(int i=len-1;i>=1;--i) {
			int nlen=i-1;
			for(int cur=0;cur<=9;++cur) {
				if(dp[i][cur]==0)continue;
				for(int next=Math.max(0,cur-1);next<=Math.min(9,cur+1);++next) {
					dp[nlen][next]+=dp[i][cur];
				}
			}
		}
		return Arrays.stream(dp[0]).sum();
	}
	
	void solve(int top,int len,int K) {
		long ans=top;
		int last=top;
		for(int pos=len-2;pos>=0;--pos) {
			int v=Math.max(0, last-1);
			while(K-get(pos+1,v)>0) {
				K-=get(pos+1,v++);
			}
			if(v>Math.max(last+1, 9))throw new AssertionError();
			ans=ans*10+v;
			last=v;
		}
		System.out.println(ans);
	}
	
	long f(int len,int v) {
		long[][] dp=new long[len][10];
		for(int i=v;i>=1;--i)dp[len-1][i]=1;
		for(int i=len-1;i>=1;--i) {
			int nlen=i-1;
			for(int cur=0;cur<=9;++cur) {
				if(dp[i][cur]==0)continue;
				for(int next=Math.max(0,cur-1);next<=Math.min(9,cur+1);++next) {
					dp[nlen][next]+=dp[i][cur];
				}
			}
			for(int next=1;next<=9;++next) {
				dp[nlen][next]+=1;
			}
		}
		return Arrays.stream(dp[0]).sum();
	}
	
	public void run() {
		FastScanner sc=new FastScanner();
		int K=sc.nextInt();
		for(int pos=13;pos>=0;--pos) {
			int v=0;
			while(K-f(pos+1,v)>0) {
				++v;
			}
			if(v>0) {
				K-=f(pos+1,v-1);
				solve(v,pos+1,K);
				return;
			}
		}
	}
	
	void tr(Object...objects) {System.out.println(Arrays.deepToString(objects));}
}

class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
    public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
        return (int) nl;
    }
    
    public double nextDouble() { return Double.parseDouble(next());}
}

Measured memory_bytes: 29268