maxn = 100005



def solve(n):

	if n<=9:

		return n

	q = [0 for i in range(maxn)]

	front = 1

	rear = 0

	for i in range(1,10):

		rear += 1

		q[rear] = i

	cnt = 9

	while 1:

		u = q[front]

		front += 1

		if u%10 != 0:

			t = u*10 + u%10 -1

			rear += 1

			q[rear] = t

			cnt += 1

			if cnt==n:

				return t

		t = u*10 + u%10

		rear += 1

		q[rear] = t

		cnt += 1

		if cnt==n:

			return t;

		if u%10 != 9:

			t = u*10 + u%10 + 1

			rear += 1

			q[rear] = t

			cnt += 1

			if cnt==n:

				return t



print((solve(int(eval(input())))))    
def solve(n):

	if n<=9:

		return n

	q = [0]

	for i in range(1,10):

		q.append(i)

	now = 1

	cnt = 9

	while 1:

		u = q[now]

		now += 1

		if u%10!=0:

			t = u*10 + u%10 - 1

			cnt += 1

			if cnt==n:

				return t

			q.append(t)

		t = u*10 + u%10

		cnt += 1

		if cnt==n:

			return t

		q.append(t)

		if u%10 !=9:

			t = u*10 + u%10 + 1

			cnt += 1

			if cnt==n:

				return t

			q.append(t)



print((solve(int(eval(input())))))
maxn = 100005


def solve(n):
    if n <= 9:
        return n
    q = [0 for i in range(maxn)]
    front = 1
    rear = 0
    for i in range(1, 10):
        rear += 1
        q[rear] = i
    cnt = 9
    while 1:
        u = q[front]
        front += 1
        if u % 10 != 0:
            t = u * 10 + u % 10 - 1
            rear += 1
            q[rear] = t
            cnt += 1
            if cnt == n:
                return t
        t = u * 10 + u % 10
        rear += 1
        q[rear] = t
        cnt += 1
        if cnt == n:
            return t
        if u % 10 != 9:
            t = u * 10 + u % 10 + 1
            rear += 1
            q[rear] = t
            cnt += 1
            if cnt == n:
                return t


print((solve(int(eval(input())))))

def solve(n):
    if n <= 9:
        return n
    q = [0]
    for i in range(1, 10):
        q.append(i)
    now = 1
    cnt = 9
    while 1:
        u = q[now]
        now += 1
        if u % 10 != 0:
            t = u * 10 + u % 10 - 1
            cnt += 1
            if cnt == n:
                return t
            q.append(t)
        t = u * 10 + u % 10
        cnt += 1
        if cnt == n:
            return t
        q.append(t)
        if u % 10 != 9:
            t = u * 10 + u % 10 + 1
            cnt += 1
            if cnt == n:
                return t
            q.append(t)


print((solve(int(eval(input())))))

-maxn = 100005 - - -    q = [0 for i in range(maxn)] -    front = 1 -    rear = 0 +    q = [0] -        rear += 1 -        q[rear] = i +        q.append(i) +    now = 1 -        u = q[front] -        front += 1 +        u = q[now] +        now += 1 -            rear += 1 -            q[rear] = t +            q.append(t) -        rear += 1 -        q[rear] = t +        q.append(t) -            rear += 1 -            q[rear] = t +            q.append(t)