You got a box with a combination lock. The lock has a display showing n digits. There are two buttons on the box, each button changes digits on the display. You have quickly discovered that the first button adds 1 to all the digits (all digits 9 become digits 0), and the second button shifts all the digits on the display one position to the right (the last digit becomes the first one). For example, if the display is currently showing number 579, then if we push the first button, the display will show 680, and if after that we push the second button, the display will show 068.

You know that the lock will open if the display is showing the smallest possible number that can be obtained by pushing the buttons in some order. The leading zeros are ignored while comparing numbers. Now your task is to find the desired number.


-----Input-----

The first line contains a single integer n (1 ≤ n ≤ 1000) — the number of digits on the display.

The second line contains n digits — the initial state of the display.


-----Output-----

Print a single line containing n digits — the desired state of the display containing the smallest possible number.


-----Examples-----
Input
3
579

Output
024

Input
4
2014

Output
0142

Difficulty: MEDIUM

Solutions:
from itertools import chain
C = 0

def main():
	input()
	ls = list(map(int, input()))
	n = len(ls)
	a = ls[-1]
	for (stop, b) in enumerate(ls):
		if b != a:
			break
	else:
		print('0' * n)
		return
	ls = ls[stop:] + ls[:stop]
	(a, l) = (ls[0], [])
	start = ma = tail = 0
	for (stop, b) in enumerate(ls):
		if b != a:
			le = stop - start
			if ma < le:
				(ma, tail) = (le, (b - a) % 10)
				l.clear()
				l.append(start)
			elif ma == le:
				tl = (b - a) % 10
				if tail > tl:
					tail = tl
					l.clear()
					l.append(start)
				elif tail == tl:
					l.append(start)
			(a, start) = (b, stop)
	le = n - start
	if ma < le:
		l.clear()
		l.append(start)
	elif ma == le:
		tl = (ls[0] - a) % 10
		if tail > tl:
			l.clear()
			l.append(start)
		elif tail == tl:
			l.append(start)
	for (i, start) in enumerate(l):
		base = ls[start]
		l[i] = ''.join((chr((a - base) % 10 + 48) for a in chain(ls[start:], ls[:start])))
	print(min(l))
main()


n = int(input())
num = input()
status = 0
check = num[0]
for i in num:
	if i != check:
		status = 1
		break
if status == 0:
	for i in range(n):
		print(0, end='')
	print()
else:
	maximum = 0
	consider = []
	for i in range(10):
		dum = ''
		for j in range(n):
			dum = dum + str((int(num[j]) + i) % 10)
		count = 0
		cur = 0
		ind = []
		for j in range(n):
			if dum[j] != '0':
				if cur > count:
					count = cur
					ind = [j - count]
				elif cur == count:
					ind.append(j - count)
				cur = 0
			else:
				cur += 1
		if cur != 0:
			if cur > count:
				count = cur
				ind = [j - count + 1]
			elif cur == count:
				ind.append(j - count + 1)
		if count > maximum:
			consider = []
			for i in ind:
				consider.append([dum, i])
				maximum = count
		elif count == maximum:
			for i in ind:
				consider.append([dum, i])
	out = []
	for i in range(len(consider)):
		out.append(consider[i][0][consider[i][1]:] + consider[i][0][:consider[i][1]])
	print(min(out))


def addOne(s):
	s = list(s)
	n = len(s)
	for i in range(n):
		if s[i] == '9':
			s[i] = '0'
		else:
			s[i] = int(s[i])
			s[i] += 1
			s[i] = str(s[i])
	return ''.join(s)
n = int(input())
s = input()
a = []
b = []
c = []
x = s
s = addOne(s)
a.append(s)
while x != s:
	s = addOne(s)
	a.append(s)
for i in a:
	if '0' in i:
		b.append(i)
for y in b:
	m = len(y)
	for j in range(0, m):
		if y[j] == '0':
			q = y[j:m] + y[0:j]
			c.append(q)
c += b
print(min(c))


def STR():
	return list(input())

def INT():
	return int(input())

def MAP():
	return map(int, input().split())

def MAP2():
	return map(float, input().split())

def LIST():
	return list(map(int, input().split()))

def STRING():
	return input()
import string
import sys
from heapq import heappop, heappush
from bisect import *
from collections import deque, Counter, defaultdict
from math import *
from itertools import permutations, accumulate
dx = [-1, 1, 0, 0]
dy = [0, 0, 1, -1]
n = INT()
s = STR()
x = []
for i in range(n):
	y1 = []
	for j in range(i, n):
		y1.append(s[j])
	for j in range(i):
		y1.append(s[j])
	x.append(y1)
ans = []
for i in range(n):
	k = 10 - int(x[i][0])
	for j in range(n):
		x[i][j] = str((k + int(x[i][j])) % 10)
	z = ''.join(x[i])
	ans.append(z)
print(min(ans))


def main():
	input()
	digits = list(map(int, input()))
	l = [digits]
	for a in range(1, 10):
		l.append([(a + b) % 10 for b in digits])
	for digits in l[:]:
		a = digits[-1]
		for (i, b) in enumerate(digits):
			if a and (not b):
				l.append(digits[i:] + digits[:i])
			a = b
	print(''.join(map(str, min(l))))

def __starting_point():
	main()
__starting_point()


def main():
	n = int(input())
	digits = list(map(int, input()))
	enum = [digits]
	for a in range(1, 10):
		enum.append([(a + b) % 10 for b in digits])
	comp = []
	for i in range(10):
		if enum[i][0] == 0:
			comp.append(enum[i])
		for j in range(1, n):
			if enum[i][j] == 0 and enum[i][j - 1] != 0:
				comp.append(enum[i][j:] + enum[i][:j])
	print(''.join(map(str, min(comp))))

def __starting_point():
	main()
__starting_point()


from collections import *

def flip(x, mi):
	return str((x + mi) % 10)

def solve():
	ans = ''.join(s)
	for i in range(n):
		mi = (10 - int(s[1])) % 10
		for j in range(n):
			s[j] = flip(int(s[j]), mi)
		s.rotate(-1)
		ans = min(ans, ''.join(s))
	return ans
(n, s) = (int(input()), deque(input()))
if n == 1:
	print(0)
else:
	print(solve())


import sys, os.path
from collections import *
from copy import *
import math
mod = 10 ** 9 + 7
if os.path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
n = int(input())
num = input()
last = num
best = num
for i in range(1000):
	if last:
		temp = ''
		l = 10 - int(last) % 10
		for i in range(n):
			t = (int(last[i]) + l) % 10
			temp += str(t)
		temp = temp[:n - 1]
		temp = '0' + temp
		last = temp
		best = min(last, best)
	else:
		break
print(str(best))


n = int(input())
l = [int(x) for x in input()]
l = l + l
g = list(l)
ans = '9' * 10000
while True:
	for x in range(0, len(l) - n):
		ans = min(ans, ''.join((str(i) for i in l[x:x + n])))
	l = [(x + 1) % 10 for x in l]
	if l == g:
		break
print(ans)


import os
import sys
from io import BytesIO, IOBase

def main():
	n = int(input())
	a = list(map(int, list(input())))
	ans = '9' * n
	temp = a.copy()
	for x in range(20):
		for z in range(n):
			temp[z] = (temp[z] + 1) % 10
		for y in range(n):
			temp = temp[-1:] + temp[:-1]
			ans = min(ans, ''.join(map(str, temp)))
	print(ans)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


n = int(input())
arr = list(map(int, input()))

def cmp(arr1, arr2):
	i = 0
	for i in range(len(arr1)):
		if arr1[i] < arr2[i]:
			return True
		elif arr1[i] > arr2[i]:
			return False
	return False
minn = arr
for i in range(n):
	if arr[i] == 0:
		tmp = arr[i:] + arr[:i]
		if cmp(tmp, minn):
			minn = tmp
	else:
		val = 10 - arr[i]
		tmp = []
		for j in range(len(arr)):
			tmp.append((arr[j] + val) % 10)
		tmp = tmp[i:] + tmp[:i]
		if cmp(tmp, minn):
			minn = tmp
for val in minn:
	print(val, end='')


import time

class na(object):
	n = 0
(na.n, num) = (int(input()), input())
start_time = time.time()
bum = []
for i in range(na.n):
	bum.append(int(num[i]))

def a(x, rec):
	rec -= 1
	x = [i - 1 if i > 0 else 9 for i in x]
	return x if rec == 0 else a(x, rec)

def b(x, rec):
	rec -= 1
	x.append(x.pop(0))
	return x if rec == 0 else b(x, rec)

def li(x):
	b = 0
	s = ''.join(map(str, x))
	b = int(s)
	return b
mins = list(bum)
remp = []
remp = bum + bum + bum
for j in range(1, 11):
	remp = [i - 1 if i > 0 else 9 for i in remp]
	for i in range(1, na.n + 2):
		mins = min(mins, remp[i:i + na.n])
m = mins
ans = ''.join(map(str, mins))
print(ans)


from collections import deque
n = int(input())
mini = input()
digits = deque(list(mini))
mini = int(mini)
for i in range(0, n):
	digits[i] = int(digits[i])
for i in range(0, n):
	k = 10 - digits[0]
	digits[0] = 0
	for j in range(1, n):
		digits[j] = (digits[j] + k) % 10
	value = int(''.join(map(str, digits)))
	if value < mini:
		mini = value
	digits.rotate(1)
print(str(mini).zfill(n))


n = int(input())
a = list(map(int, input()))
ans = a[:]
for i in range(n):
	b = [0] * n
	for j in range(n):
		b[j] = (a[(i + j) % n] - a[i]) % 10
	ans = min(ans, b)
print(''.join(map(str, ans)))


def modify(string, index):
	if string[index] == '0':
		key = 0
	else:
		key = 10 - int(string[index])
	bad = ''
	for i in string:
		bad += str((int(i) + key) % 10)
	return bad[index:] + bad[:index]
x = int(input())
y = input()
minx = 'zzzzzzzzz'
for i in range(x):
	minx = min(minx, modify(y, i))
print(minx)


n = int(input())
z = input()
a = list(map(int, z))
for x in [a[i:] + a[:i] for i in range(n)]:
	s = ''
	for y in x:
		s += str((y + 10 - x[0]) % 10)
	if s < z:
		z = s
print(z)


n = int(input())
state = [int(c) for c in input()]
min_s = state
for i in range(n):
	tmp = state[i:] + state[:i]
	tmp_min = [tmp[i] - tmp[0] for i in range(n)]
	for i in range(n):
		if tmp_min[i] < 0:
			tmp_min[i] += 10
	if tmp_min < min_s:
		min_s = tmp_min
print(''.join(map(str, min_s)))


n = int(input())
l = list(map(int, [x for x in input()]))
m = [9] * (n + 1)
for i in range(len(l)):
	x = list(l[i + 1:]) + list(l[:i + 1])
	s = x[0]
	for j in range(len(x)):
		x[j] = (x[j] - s) % 10
	if x < m:
		m = x
print(''.join(list(map(str, m))))


n = int(input())
a = [x for x in input()]
ans = ''.join(a)
for i in range(10):
	a = [chr(ord('0') + (ord(x) - ord('0') + 1) % 10) for x in a]
	for j in range(n):
		ans = min(ans, ''.join(a[j:] + a[:j]))
print(ans)


def upshift(s):
	for i in range(n):
		if s[i] == '9':
			s[i] = '0'
		else:
			s[i] = chr(ord(s[i]) + 1)
	return s

def lshift(s):
	k = [s[n - 1]]
	for i in range(0, n - 1):
		k.append(s[i])
	s = k
	return s

def copy(s):
	k = []
	for i in s:
		k.append(i)
	return k
n = int(input())
s = list(str(input()))
small = copy(s)
for i in range(n):
	s = lshift(s)
	for j in range(10):
		s = upshift(s)
		if small > s:
			small = copy(s)
for i in small:
	print(i, end='')


n = int(input())
t = int(input())
min = t
a = []
for i in range(n):
	a.append(t % 10)
	t //= 10
for i in range(n):
	k = (10 - a[n - 1]) % 10
	l = 1
	new = 0
	for j in range(n):
		new += (a[j] + k) % 10 * l
		l *= 10
	if new < min:
		min = new
	a.append(a[0])
	a.pop(0)
print('0' * (n - len(str(min))) + str(min))


n = int(input())
a = list(input())
ans = a
for i in range(10):
	for j in range(n):
		if a < ans:
			ans = a
		a = a[1:] + [a[0]]
	for j in range(n):
		a[j] = str((int(a[j]) + 1) % 10)
print(''.join(ans))


from itertools import chain

def main():
	n = int(input())
	aa = list(map(int, input()))
	res = []
	for j in range(len(aa)):
		(y, base) = (0, aa[j])
		for x in chain(aa[j:], aa[:j]):
			y = y * 10 + (x - base) % 10
		res.append(y)
	f = str(len(aa)).join(('{:0>', 'd}'))
	print(f.format(min(res)))

def __starting_point():
	main()
__starting_point()


n = int(input())
nums = list(map(int, input()))

def incrementNums(nums):
	for i in range(n):
		if nums[i] + 1 > 9:
			nums[i] = 0
		else:
			nums[i] += 1

def smallest(str1, str2):
	for i in range(len(str1)):
		if str1[i] < str2[i]:
			return str1
		elif str1[i] > str2[i]:
			return str2
	return str1
lowest = []
for i in range(n):
	lowest.append(9)
lowest = smallest(nums, lowest).copy()
for i in range(10):
	for j in range(n):
		nums.insert(0, nums.pop())
		lowest = smallest(nums, lowest).copy()
	incrementNums(nums)
	lowest = smallest(nums, lowest).copy()
print(str(''.join(map(str, lowest))).rjust(n, '0'))


from __future__ import print_function
from collections import Counter, OrderedDict
from itertools import permutations as perm
from fractions import Fraction
from collections import deque
from sys import stdin
from bisect import *
from heapq import *
from math import *
g = lambda : stdin.readline().strip()
gl = lambda : g().split()
gil = lambda : [int(var) for var in gl()]
gfl = lambda : [float(var) for var in gl()]
gcl = lambda : list(g())
gbs = lambda : [int(var) for var in g()]
mod = int(1000000000.0) + 7
(n,) = gil()
s = g()
ans = s

def solve(s):
	ans = s
	t = []
	for i in range(10):
		for c in s:
			v = int(c) + i
			if v > 9:
				v -= 10
			t.append(str(v))
		ans = min(ans, ''.join(t))
		t.clear()
	return ans
for i in range(n):
	ans = min(ans, solve(s[i:] + s[:i]))
print(ans)


n = int(input())
d = input()
s = []
for i in d:
	s.append(int(i))
pos = 0
ans = 10 ** 1000
for i in range(1, len(s)):
	if s[i] == s[i - 1]:
		continue
	else:
		x = s[pos]
		t = [s[j] for j in range(len(s))]
		for j in range(len(t)):
			t[j] = (t[j] + 10 - x) % 10
		A = [0] * n
		for j in range(len(t)):
			A[j] = t[(j + pos) % n]
		a = int(''.join(list(map(str, A))))
		if a < ans:
			ans = a
		pos = i
x = s[pos]
for i in range(len(s)):
	s[i] = (s[i] + 10 - x) % 10
A = [0] * n
for i in range(len(s)):
	A[i] = s[(i + pos) % n]
a = int(''.join(list(map(str, A))))
if a < ans:
	ans = a
print('0' * (n - len(str(ans))) + str(ans))


def main():
	n = int(input())
	d = input()
	best_d = d
	for _ in range(10):
		for _ in range(n):
			d = d[-1:] + d[:-1]
			if d < best_d:
				best_d = d
		d = ''.join([str((int(i) + 1) % 10) for i in d])
		if d < best_d:
			best_d = d
	return best_d
print(main())


def main():
	n = int(input())
	digits = list(map(int, input()))
	enum = [digits]
	for a in range(1, 10):
		enum.append([(a + b) % 10 for b in digits])
	for digits in enum[:10]:
		for j in range(n):
			if digits[j - 1] and (not digits[j]):
				enum.append(digits[j:] + digits[:j])
	print(''.join(map(str, min(enum))))
main()


n = int(input())
a = [int(c) for c in input()]
print(''.join((str(x) for x in min(([(x + i) % 10 for x in a[j:] + a[:j]] for j in range(n) for i in range(10))))))


def norm(s):
	return [(x + 10 - s[0]) % 10 for x in s]
(n,) = map(int, input().split())
s = input().strip()
s = [int(x) for x in s]
print(''.join(map(str, min([norm(s[j:] + s[:j]) for j in range(n)]))))


(n, q) = (int(input()), [9])
t = [int(c) for c in input()]
for i in range(n):
	p = [(s - t[0]) % 10 for s in t]
	if p < q:
		q = p
	t.append(t.pop(0))
print(''.join(map(str, q)))


n = int(input())
s = [int(d) for d in input()]
ans = []
for k in range(n):
	cycle = s[k:] + s[:k]
	shift = -cycle[0] % 10
	for i in range(n):
		cycle[i] = str((cycle[i] + shift) % 10)
	ans.append(int(''.join(cycle)))
print(str(min(ans)).zfill(n))


num = int(input())
digits = [i for i in input()]
ans = ''.join(digits)
a = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
for i in range(0, -10, -1):
	temp = [str(a[int(k) + i]) for k in digits]
	for j in range(num):
		temp1 = temp[j:] + temp[:j]
		ans = min(ans, ''.join(temp1))
print(ans)


from sys import stdin

def decr(n):
	return [(d + 10 - n[0]) % 10 for d in n]

def rotate(n):
	return n[1:] + [n[0]]
for s in stdin:
	s = input()
	n = [int(c) for c in s]
	m = [9] * len(n)
	for i in range(len(n)):
		n = rotate(n)
		d = decr(n)
		m = min(m, d)
	for d in m:
		print(d, end='')
	print()


def main(n, a):
	a = ('{:0' + '{}'.format(n) + 'd}').format(int(a))
	mn = int(a)
	for j in range(n):
		x = list(a[j:] + a[:j])
		y = x.copy()
		i = 10 - int(y[0])
		x = y.copy()
		for k in range(n):
			x[k] = str((int(x[k]) + i) % 10)
		if int(''.join(x)) < mn:
			mn = int(''.join(x))
	print(('{:0' + '{}'.format(n) + 'd}').format(mn))

def main_input():
	n = int(input())
	a = int(input())
	main(n, a)

def __starting_point():
	main_input()
__starting_point()


import io, os, sys
from atexit import register
from functools import cmp_to_key
tokens = []
tokens_next = 0

def next_str():
	global tokens, tokens_next
	while tokens_next >= len(tokens):
		tokens = input().split()
		tokens_next = 0
	tokens_next += 1
	return tokens[tokens_next - 1]

def nextInt():
	return int(next_str())
n = nextInt()
s = next_str()
s = list(map(int, list(s)))
res = s

def f(ind):
	return (ind + n) % n

def my_compare(a, b):
	for i in range(n):
		cur = s_new[f(a + i)] - s_new[f(b + i)]
		if cur != 0:
			return cur
	return 0
for i in range(-10, 10):
	s_new = map(lambda x: (x + i + 10) % 10, s)
	s_new = list(s_new)
	indices = list(range(n))
	best = sorted(indices, key=cmp_to_key(my_compare))[0]
	res = min(res, s_new[best:] + s_new[0:best])
print(''.join(map(str, res)))


n = int(input())
s = input()
i = 0
min_ = int(s)
s1 = s
i = 0
while i <= n:
	s = s[1:] + s[0]
	if int(s[0]) != 0:
		g = 9 - int(s[0]) + 1
		s2 = ''
		for j in range(len(s)):
			h = int(s[j]) + g
			if h >= 10:
				h = abs(10 - h)
			s2 = s2 + str(h)
		s = s2
	if int(s) < min_:
		min_ = int(s)
		s1 = s
	i = i + 1
print(s1)


n = int(input())
l = list(map(int, list(input())))

def minit(l):
	dec = l[0]
	for i in range(len(l)):
		l[i] = (l[i] - dec + 10) % 10
	return l
ans = [float('+inf')]
for i in range(n):
	mm = minit(l[:])
	ans = min(mm, ans)
	l = l[1:] + [l[0]]
print(''.join(map(str, ans)))


numDigits = int(input().strip())
number = input().strip()
minVal = -1
finalString = ''

def shiftDigits(numDigits, number):
	newStr = number[1:] + number[0]
	return newStr

def addDigit(digit, adder):
	return (digit + adder) % 10

def addDigits(numDigits, number):
	newStr = ''
	first = int(number[0])
	diff = 10 - first
	for x in number:
		newStr += str(addDigit(int(x), diff))
	return newStr
testStr = number
for a in range(numDigits):
	testStr = shiftDigits(numDigits, testStr)
	testStr = addDigits(numDigits, testStr)
	testNum = int(testStr)
	if testNum < minVal or minVal == -1:
		minVal = int(testNum)
		finalString = testStr
print(finalString)


n = int(input())
c = list(map(int, input()))
val = list(c)
for i in range(n):
	d = (10 - c[0]) % 10
	for j in range(n):
		c[j] = (c[j] + d) % 10
	if c < val:
		val = list(c)
	c.append(c[0])
	del c[0]
print(''.join(map(str, val)))


n = int(input())
s = [int(c) for c in input()]
ans = [10]
for i in range(n):
	s = s[1:] + [s[0]]
	pwd = [0]
	for j in range(1, n):
		d = (pwd[-1] + s[j] - s[j - 1]) % 10
		pwd.append(d)
	if ans > pwd:
		ans = pwd
for d in ans:
	print(d, end='')


n = int(input())
a = [int(i) for i in list(input())]
best = None

def toInt(a, i):
	copy = [str(i) for i in a]
	return int(''.join(copy[i:]) + ''.join(copy[:i]))
for z in range(10):
	for j in range(len(a)):
		if a[j] == 9:
			a[j] = 0
		else:
			a[j] += 1
	for i in range(len(a)):
		if a[i] == 0:
			if best == None:
				best = toInt(a, i)
			else:
				best = min(best, toInt(a, i))
print(str(best).zfill(n))


import os
import sys
from math import *
from collections import *
from bisect import *
from io import BytesIO, IOBase

def vsInput():
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def value():
	return tuple(map(int, input().split()))

def array():
	return [int(i) for i in input().split()]

def Int():
	return int(input())

def Str():
	return input()

def arrayS():
	return [i for i in input().split()]
n = Int()
s = input()
ans = int(s)
for i in range(n):
	number = s[i] + s[i + 1:] + s[:i]
	add = 10 - int(s[i])
	num = 0
	for j in range(n):
		num = num * 10 + (int(number[j]) + add) % 10
	ans = min(num, ans)
print('0' * (n - len(str(ans))), ans, sep='')


n = int(input())
s = input()
ans = '9' * n
for _ in range(10):
	for i in range(n):
		ans = min(ans, s[i:] + s[:i])
	t = ''
	for ch in s:
		t += str((int(ch) + 1) % 10)
	s = t
print(ans)


def shift(t):
	return t[-1] + t[0:len(t) - 1]

def add(t):
	tt = []
	tt = [i for i in t]
	tt = list(map(lambda x: '0' if x == '9' else chr(ord(x) + 1 % 10), tt))
	return ''.join(tt)

def main():
	n = int(input())
	s = input()
	s0 = s
	smin = s0
	t0 = s0
	while 1:
		while 1:
			s = add(s)
			smin = min(smin, s)
			if s == t0:
				break
		s = shift(s)
		t0 = s
		if t0 == s0:
			break
	print(smin)
main()


n = int(input())
s = input()
li = [int(i) for i in s]
mi = [9 for i in range(n)]
for i in range(n):
	a = [0]
	for j in range(i + 1, n):
		if li[j] - li[i] < 0:
			a.append(li[j] - li[i] + 10)
		else:
			a.append(li[j] - li[i])
	for j in range(0, i):
		if li[j] - li[i] < 0:
			a.append(li[j] - li[i] + 10)
		else:
			a.append(li[j] - li[i])
	fl = 0
	for j in range(n):
		if mi[j] < a[j]:
			fl = 0
			break
		elif mi[j] > a[j]:
			fl = 1
			break
	if fl == 1:
		mi = [j for j in a]
mi = [str(i) for i in mi]
print(''.join(mi))


def minimize(num):
	num = step(num, (10 - num[0]) % 10)
	return num

def shift(num):
	numb = [num[-1]]
	numb.extend(num[:-1])
	return numb

def step(num, val):
	numb = []
	for n in num:
		numb.append((n + val) % 10)
	return numb
digits = int(input())
strnumber = list(input())
number = []
for n in strnumber:
	number.append(int(n))
redux = []
for i in number:
	numb = shift(number)
	res = minimize(number)
	strres = ''
	for c in res:
		strres += str(c)
	redux.append(int(strres))
	number = numb
final = min(redux)
strfinal = str(final)
print('0' * (digits - len(strfinal)) + strfinal)


n = int(input())
stri = input()
st = [int(x) for x in stri]
if len(st) == 1:
	print(0)
else:
	n = len(st)
	a = (st[1] - st[0]) % 10
	j = 0
	for i in range(1, n):
		if i != n - 1:
			if (st[i + 1] - st[i]) % 10 < a:
				j = i
				a = (st[i + 1] - st[i]) % 10
			elif (st[i + 1] - st[i]) % 10 == a:
				p = i
				q = j
				for k in range(2, n):
					if p + k >= n:
						b1 = (st[p + k - n] - st[p]) % 10
					else:
						b1 = (st[p + k] - st[p]) % 10
					if q + k >= n:
						b2 = (st[q + k - n] - st[q]) % 10
					else:
						b2 = (st[q + k] - st[q]) % 10
					if b2 > b1:
						j = i
						a = (st[i + 1] - st[i]) % 10
						break
					if b1 > b2:
						break
		elif (st[0] - st[n - 1]) % 10 < a:
			j = i
			a = (st[0] - st[n - 1]) % 10
		elif (st[0] - st[n - 1]) % 10 == a:
			p = i
			q = j
			for k in range(2, n):
				if p + k >= n:
					b1 = (st[p + k - n] - st[p]) % 10
				else:
					b1 = (st[p + k] - st[p]) % 10
				if q + k >= n:
					b2 = (st[q + k - n] - st[q]) % 10
				else:
					b2 = (st[q + k] - st[q]) % 10
				if b2 > b1:
					j = i
					a = (st[i + 1] - st[i]) % 10
					break
				if b1 > b2:
					break
	ans = st[0:j]
	st = st[j:n] + ans
	b = 10 - st[0]
	for i in range(n):
		st[i] = (st[i] + b) % 10
		print(st[i], end='')


def main():
	n = int(input())
	s = list(input())
	t = list(s)
	if s[0] != '0':
		k = ord('0') + 10 - ord(s[0])
		for i in range(n):
			t[i] = chr(ord('0') + (ord(s[i]) - ord('0') + k) % 10)
	curr = ''.join(t)
	for i in range(1, n):
		if s[i] == '0':
			t = s[i:] + s[:i]
			curr = min(curr, ''.join(t))
		else:
			k = ord('0') + 10 - ord(s[i])
			t = s[i:] + s[:i]
			for j in range(n):
				t[j] = chr(ord('0') + (ord(t[j]) - ord('0') + k) % 10)
			curr = min(curr, ''.join(t))
	print(curr)
main()


length = int(input())
number = input()

def addn(n, a):
	num = str(n)
	s = ''
	for i in num:
		ad = int(i) + a
		if ad > 9:
			ad = ad - 10
		s = s + str(ad)
	return s
ans = int(number)
for j in range(length):
	add = 10 - int(number[j])
	temp = number[j:] + number[:j]
	if add == 0:
		lock = int(temp)
	else:
		lock = int(addn(temp, add))
	if lock < ans:
		ans = lock
an = str(ans)
for each in range(len(an), length):
	an = '0' + an
print(an)


class CodeforcesTask496BSolution:

	def __init__(self):
		self.result = ''
		self.n = 0
		self.digits = []

	def read_input(self):
		self.n = int(input())
		self.digits = [int(x) for x in input()]

	def process_task(self):
		nums = []
		for x in range(10):
			nums.append([(y + x) % 10 for y in self.digits])
		numbers = []
		for x in range(self.n):
			for y in range(10):
				numbers.append(int(''.join([str(z) for z in nums[y][x:] + nums[y][:x]])))
		self.result = '0' * (self.n - len(str(min(numbers)))) + str(min(numbers))

	def get_result(self):
		return self.result
Solution = CodeforcesTask496BSolution()
Solution.read_input()
Solution.process_task()
print(Solution.get_result())


n = int(input())
s = input()
mn = s
for shift in range(n):
	copy = s[n - shift:] + s[:n - shift]
	add = 10 - int(copy[0])
	ans = ''
	for dig in range(n):
		ans += str((int(copy[dig]) + add) % 10)
	if int(ans) < int(mn):
		mn = ans
print(mn)


n = int(input())
a = [int(i) for i in list(input())]
m = a
for i in range(1, n + 1):
	t = a[i:] + a[:i]
	x = t[0]
	for k in range(n):
		t[k] = (t[k] - x) % 10
	m = min(m, t)
print(''.join((str(i) for i in m)))


from itertools import chain
C = 0

def main():
	input()
	s = input()
	n = len(s)
	a = s[-1]
	for (stop, b) in enumerate(s):
		if b != a:
			break
	else:
		print('0' * n)
		return
	s = ''.join((s[stop:], s[:stop]))
	(a, start) = (s[0], 0)
	(ma, l) = (0, [])
	for (stop, b) in enumerate(s):
		if b != a:
			le = stop - start
			if ma < le:
				ma = le
				l.clear()
				l.append(start)
			elif ma == le:
				l.append(start)
			(a, start) = (b, stop)
	le = n - start
	if ma < le:
		l.clear()
		l.append(start)
	elif ma == le:
		l.append(start)
	for (i, start) in enumerate(l):
		base = int(s[start])
		l[i] = ''.join((chr((int(c) - base) % 10 + 48) for c in chain(s[start:], s[:start])))
	print(min(l))

def __starting_point():
	main()
__starting_point()


(n, s) = (int(input()), [int(x) for x in input()])
print(''.join(map(str, min([[(x + 10 - s[j]) % 10 for x in s[j:] + s[:j]] for j in range(n)]))))


n = int(input())
x = input()
a = [x]
temp = x
for j in range(0, 9):
	for i in range(0, n):
		if temp[i] == '9':
			f = list(temp)
			f[i] = '0'
			temp = ''.join(f)
		else:
			s = list(temp)
			s[i] = str(int(s[i]) + 1)
			temp = ''.join(s)
	a.append(temp)
ans = []
for i in range(0, 10):
	for j in range(0, n):
		temp = a[i][n - 1]
		a[i] = a[i][:n - 1]
		a[i] = temp + a[i]
		ans.append(a[i])
print(min(ans))


n = int(input())
x = input()
l = list(map(int, x))
for i in range(n):
	l[i] = x[i:] + x[:i]
for i in range(n):
	u = ''
	d = 10 - int(l[i][0])
	for j in range(n):
		u += str((int(l[i][j]) + d) % 10)
	l[i] = u
print(min(l))


def maxScore(ctr, n):
	s = str(ctr).zfill(n)
	assert len(s) == n
	best = int(s)
	for posOffset in range(n):
		for valueOffset in range(10):
			gen = ''
			for i in range(n):
				gen += str((int(s[(i + posOffset) % n]) + valueOffset) % 10)
			best = min(best, int(gen))
	return str(best).zfill(n)
n = int(input())
s = int(input())
print(maxScore(s, n))


n = int(input())
l = list(input())
for i in range(n):
	l[i] = int(l[i])
ans = 10 ** (n - 1)
for i in range(n):
	l = l[1:] + l[:1]
	m = []
	for j in range(n):
		m.append(l[j])
	for j in range(1, n):
		m[j] -= m[0]
		if m[j] < 0:
			m[j] += 10
	m[0] = 0
	cur = ''
	for j in range(n):
		cur += str(m[j])
	ans = min(ans, int(cur))
ans = str(ans)
while len(ans) < n:
	ans = '0' + ans
print(ans)


n = int(input())
num = input()
digits = tuple(map(int, num))

def increment(digits, i):
	return tuple(map(lambda n: (n + i) % 10, digits))

def shift(l):
	if len(l) == 1:
		return l
	return l[1:] + l[:1]
combs = []
for k in range(10):
	combs.append(digits)
	digits = increment(digits, 1)
	for i in range(len(digits) - 1):
		combs.append(digits)
		digits = shift(digits)
print(''.join(map(str, min(combs))))


from sys import stdin

def inc(ch, i):
	return str(int(ch) + i)[-1]
l = int(stdin.readline())
n = input()
res = n
mr = int(n)
for i in range(l):
	for j in range(10):
		seq = ''.join([inc(ch, j) for ch in n])
		r = seq[i:] + seq[:i]
		if int(r) < mr:
			mr = int(r)
			res = r
print(res)


import sys

def fastio():
	from io import StringIO
	from atexit import register
	global input
	sys.stdin = StringIO(sys.stdin.read())
	input = lambda : sys.stdin.readline().rstrip('\r\n')
	sys.stdout = StringIO()
	register(lambda : sys.__stdout__.write(sys.stdout.getvalue()))
fastio()

def debug(*var, sep=' ', end='\n'):
	print(*var, file=sys.stderr, end=end, sep=sep)
INF = 10 ** 20
MOD = 10 ** 9 + 7
I = lambda : list(map(int, input().split()))
from math import gcd
from math import ceil
from collections import defaultdict as dd, Counter
from bisect import bisect_left as bl, bisect_right as br
(n,) = I()
a = [int(i) for i in input()]
m = min(a)
ans = a
for i in range(n):
	cur = a[i:] + a[:i]
	to_add = 10 - cur[0]
	for i in range(n):
		cur[i] += to_add
		cur[i] %= 10
	ans = min(ans, cur)
print(''.join([str(i) for i in ans]))


import math, sys
from collections import defaultdict, deque
import bisect as bi

def yes():
	print('YES')

def no():
	print('NO')

def I():
	return int(sys.stdin.readline())

def In():
	return map(int, sys.stdin.readline().split())

def Sn():
	return sys.stdin.readline().strip()

def dict(a):
	d = {}
	for x in a:
		if d.get(x, -1) != -1:
			d[x] += 1
		else:
			d[x] = 1
	return d

def find_gt(a, x):
	i = bi.bisect_left(a, x)
	if i != len(a):
		return i
	else:
		return -1

def main():
	try:
		n = I()
		s = Sn()
		mx = int(s)
		ok = False
		for i in range(n):
			z = 10 - int(s[-1])
			t = [str((int(s[i]) + z) % 10) for i in range(n)]
			mx = min(mx, int(''.join([t[-1]] + t[:n - 1])))
			s = s[-1] + s[:n - 1]
		mx = str(mx)
		for i in range(n - len(mx)):
			mx = '0' + mx
		print(mx)
	except:
		pass
M = 998244353
P = 1000000007
for _ in range(1):
	main()


from sys import stdin

def decr(n):
	return map(lambda v: (v - n[0] + 10) % 10, n)

def rotate(n):
	return [n[-1]] + n[:-1]
for a in stdin:
	a = input()
	n = [int(v) for v in a]
	m = len(n) * [9]
	for i in range(len(n)):
		n = rotate(n)
		d = list(decr(n))
		if d < m:
			m = d
	for v in m:
		print(v, end='')
	print()


def shift(num):
	return num[-1] + num[:-1]

def plus_one(num):
	result = ''
	for digit in num:
		new_digit = int(digit) + 1
		if new_digit == 10:
			result += '0'
		else:
			result += str(new_digit)
	return result
n = int(input())
num = input()
ans = int(num)
for i in range(10):
	for j in range(n):
		num = shift(num)
		if int(num) < ans:
			ans = int(num)
	num = plus_one(num)
ans = str(ans)
if len(ans) < n:
	ans = '0' * (n - len(ans)) + ans
print(ans)


from itertools import tee
from collections import deque

def inc(ns, e):
	new_ns = [str((int(n) + e) % 10) for n in ns]
	return ''.join(new_ns)

def rotate(ns):
	return ''.join((ns[1:], ns[0]))

def main(ns):
	curr_min = (float('inf'), None)
	for _ in range(len(ns)):
		new_s = inc(ns, -1 * int(ns[0]))
		if int(new_s) < curr_min[0]:
			curr_min = (int(new_s), new_s)
		ns = rotate(ns)
	print(curr_min[1])
input()
main(input())


n = int(input())
s = [int(i) for i in input()]
k = [1 for i in range(n)]
for i in range(n):
	if [(u + (10 - s[i - 1]) % 10) % 10 for u in s[i - 1:]] + [(u + (10 - s[i - 1]) % 10) % 10 for u in s[:i - 1]] < k:
		k = [(u + (10 - s[i - 1]) % 10) % 10 for u in s[i - 1:]] + [(u + (10 - s[i - 1]) % 10) % 10 for u in s[:i - 1]]
ans = ''
for i in k:
	ans += str(i)
print(ans)


R = lambda : map(int, input().split())
n = int(input())
nums = [int(c) for c in input()]
res = [9] * 1006
for i in range(n):
	wnms = nums[i:] + nums[:i]
	res = min([res] + [[(wnms[k] + j) % 10 for k in range(n)] for j in range(10)])
print(''.join(map(str, res)))


from ast import NameConstant
import bisect
import sys
import math

def input():
	return sys.stdin.readline().strip()

def iinput():
	return int(input())

def minput():
	return map(int, sys.stdin.readline().strip().split())

def listinput():
	return list(map(int, sys.stdin.readline().strip().split()))
n = int(input())
a = list(map(int, input()))
number_possible = []
while True:
	for i in range(n):
		a[i] += 1
		if a[i] == 10:
			a[i] = 0
	s = ''
	for i in range(n):
		s += str(a[i])
	if s not in number_possible:
		number_possible.append(s)
	else:
		break
for i in range(len(number_possible)):
	temp = number_possible[i]
	possible = [temp]
	while True:
		temp = temp[1:] + temp[:1]
		if temp not in possible:
			possible.append(temp)
		else:
			break
	number_possible[i] = min(possible)
print(min(number_possible))


n = int(input())
a = input()
d = a
for i in range(10):
	for j in range(n):
		a = a[n - 1] + a[:n - 1]
		if a < d:
			d = a
	l = list(a)
	for j in range(n):
		l[j] = chr(ord(l[j]) + 1)
		if l[j] == ':':
			l[j] = '0'
	a = ''.join(l)
	if a < d:
		d = a
print(d)


class na(object):
	n = 0
(na.n, num) = (int(input()), input())
bum = []
for i in range(na.n):
	bum.append(int(num[i]))

def a(x, rec):
	rec -= 1
	x = [i - 1 if i > 0 else 9 for i in x]
	return x if rec == 0 else a(x, rec)

def b(x, rec):
	rec -= 1
	x.append(x.pop(0))
	return x if rec == 0 else b(x, rec)

def li(x):
	b = 0
	for i in range(na.n):
		b += x[i] * 10 ** (na.n - i - 1)
	return b

def li_redifined(x, m):
	for i in range(na.n):
		if x[i] < m[i]:
			return x
		elif m[i] < x[i]:
			return m
	return m
temp = list(bum)
for j in range(1, 11):
	bum = a(bum[:], 1)
	for i in range(1, na.n + 2):
		bum = b(bum[:], 1)
		temp = li_redifined(bum[:], temp)
m = li(temp)
print(repr(m).rjust(na.n, '0'))


n = int(input())
s = input()
a = [0] * n
for i in range(n):
	a[i] = s[i:] + s[:i]
for i in range(n):
	u = ''
	d = 10 - int(a[i][0])
	for j in range(n):
		u += str((int(a[i][j]) + d) % 10)
	a[i] = u
print(min(a))


n = int(input())
s = input()
ans = [0] * n
for i in range(n):
	ans[i] = s[i:] + s[:i]
for i in range(n):
	v = ''
	d = 10 - int(ans[i][0])
	for j in range(n):
		x = (d + int(ans[i][j])) % 10
		v += str(x)
	ans[i] = v
print(min(ans))


n = int(input())
d = input()
c = d
s = '1'
m = 10 ** 1005
for k in range(0, 11):
	for i in range(0, n):
		c = c[:i] + str((int(c[i]) + 1) % 10) + c[i + 1:]
	for i in range(0, n):
		c = c[1:] + c[0]
		b = int(c)
		if b < m:
			m = b
			s = c
print(s)


n = int(input())
a = input()
b = [int(c) for c in a]
ans = 0
for i in range(1, n):
	for k in range(1, n):
		if (b[(i + k) % n] - b[i] + 10) % 10 < (b[(ans + k) % n] - b[ans] + 10) % 10:
			ans = i
			break
		elif (b[(i + k) % n] - b[i] + 10) % 10 > (b[(ans + k) % n] - b[ans] + 10) % 10:
			break
for i in range(0, n):
	print('%d' % ((b[(ans + i) % n] - b[ans]) % 10), end='')


import sys
input = sys.stdin.readline

def ceil(x):
	if x != int(x):
		x = int(x) + 1
	return x

def factorial(x, m):
	val = 1
	while x > 0:
		val = val * x % m
		x -= 1
	return val

def fact(x):
	val = 1
	while x > 0:
		val *= x
		x -= 1
	return val

def swaparr(arr, a, b):
	temp = arr[a]
	arr[a] = arr[b]
	arr[b] = temp

def gcd(a, b):
	if b == 0:
		return a
	return gcd(b, a % b)

def nCr(n, k):
	if k > n:
		return 0
	if k > n - k:
		k = n - k
	res = 1
	for i in range(k):
		res = res * (n - i)
		res = res / (i + 1)
	return int(res)

def upper_bound(a, x, lo=0, hi=None):
	if hi == None:
		hi = len(a)
	while lo < hi:
		mid = (lo + hi) // 2
		if a[mid] < x:
			lo = mid + 1
		else:
			hi = mid
	return lo

def primefs(n):
	primes = {}
	while n % 2 == 0 and n > 0:
		primes[2] = primes.get(2, 0) + 1
		n = n // 2
	for i in range(3, int(n ** 0.5) + 2, 2):
		while n % i == 0 and n > 0:
			primes[i] = primes.get(i, 0) + 1
			n = n // i
	if n > 2:
		primes[n] = primes.get(n, 0) + 1
	return primes

def power(x, y, p):
	res = 1
	x = x % p
	if x == 0:
		return 0
	while y > 0:
		if y & 1 == 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def swap(a, b):
	temp = a
	a = b
	b = temp
	return (a, b)

def find(x, link):
	p = x
	while p != link[p]:
		p = link[p]
	while x != p:
		nex = link[x]
		link[x] = p
		x = nex
	return p

def union(x, y, link, size):
	x = find(x, link)
	y = find(y, link)
	if size[x] < size[y]:
		(x, y) = swap(x, y)
	if x != y:
		size[x] += size[y]
		link[y] = x

def sieve(n):
	prime = [True for i in range(n + 1)]
	(prime[0], prime[1]) = (False, False)
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	return prime
MAXN = int(100000.0 + 5)

def spf_sieve():
	spf[1] = 1
	for i in range(2, MAXN):
		spf[i] = i
	for i in range(4, MAXN, 2):
		spf[i] = 2
	for i in range(3, ceil(MAXN ** 0.5), 2):
		if spf[i] == i:
			for j in range(i * i, MAXN, i):
				if spf[j] == j:
					spf[j] = i
spf = [0 for i in range(MAXN)]

def factoriazation(x):
	res = []
	for i in range(2, int(x ** 0.5) + 1):
		while x % i == 0:
			res.append(i)
			x //= i
	if x != 1:
		res.append(x)
	return res

def int_array():
	return list(map(int, input().strip().split()))

def float_array():
	return list(map(float, input().strip().split()))

def str_array():
	return input().strip().split()
MOD = int(1000000000.0) + 7
CMOD = 998244353
INF = float('inf')
NINF = -float('inf')
from itertools import permutations
import math
from bisect import bisect_left

def solve():
	n = int(input())
	mystring = input().rstrip()
	s = list(map(int, [x for x in mystring]))
	print(''.join(map(str, min(([(x + 10 - s[i]) % 10 for x in s[i:] + s[:i]] for i in range(n))))))
for _ in range(1):
	solve()


def less(a, b):
	for i in range(len(a)):
		elem1 = a[i]
		elem2 = b[i]
		if elem1 < elem2:
			return True
		elif elem1 > elem2:
			return False
	return False
n = int(input())
s = input()
min = [9] * n
minK = -1
for i in range(n):
	k = 10 - int(s[i])
	cur = [0]
	for j in range(i + 1, n):
		cur.append((int(s[j]) + k) % 10)
	for j in range(i):
		cur.append((int(s[j]) + k) % 10)
	if less(cur, min):
		min = cur
		minK = i
cur = [0]
k = 10 - int(s[minK])
for j in range(minK + 1, n):
	cur.append((int(s[j]) + k) % 10)
for j in range(minK):
	cur.append((int(s[j]) + k) % 10)
print(''.join(map(str, cur)))


def main():
	n = int(input())
	digits = list(map(int, input()))
	min_val = float('inf')
	for i in range(n):
		req = 10 - digits[i]
		digits_copy = digits[:]
		for j in range(n):
			digits_copy[j] += req
			if digits_copy[j] >= 10:
				digits_copy[j] -= 10
		num = ''
		for j in range(i, n):
			num += str(digits_copy[j])
		for j in range(i):
			num += str(digits_copy[j])
		min_val = min(min_val, int(num))
	min_val = str(min_val)
	if len(min_val) < n:
		min_val = '0' * (n - len(min_val)) + min_val
	print(min_val)
main()


def parser():
	while 1:
		data = list(input().split(' '))
		for number in data:
			if len(number) > 0:
				yield number
input_parser = parser()

def get_word():
	global input_parser
	return next(input_parser)

def get_number():
	data = get_word()
	try:
		return int(data)
	except ValueError:
		return float(data)
n = get_number()
c = get_word()
b = list(c)
a = [int(i) for i in b]
min_val = int(c)
new_a = a.copy()
for i in range(n):
	tmp = new_a.copy()
	while tmp[0] != 0:
		tmp = [int((i + 1) % 10) for i in tmp]
	val = int(''.join([str(i) for i in tmp]))
	if val < min_val:
		min_val = val
	last = new_a[-1]
	new_a[1:] = new_a[:-1]
	new_a[0] = last
min_val = list(str(min_val))
x = b
x[:n - len(min_val)] = '0' * (n - len(min_val))
x[n - len(min_val):] = min_val[:]
print(''.join(x))


def input_split(f):
	return map(f, input().split())

def main():
	n = int(input())
	num = input()
	res = num
	tmp = num
	for i in range(10):
		tmp = ''.join(map(str, [(int(x) + i) % 10 for x in num]))
		for j in range(n):
			res = min(res, tmp[j:] + tmp[:j])
	print(res)
main()


n = int(input())
num = input()
num = [list(num) for _ in range(10)]
for i in range(10):
	for j in range(n):
		num[i][j] = (int(num[i][j]) + i) % 10
col = []
for i in range(10):
	for j in range(n):
		col.append(num[i][j:] + num[i][:j])
ans = ''.join(list(map(str, min(col))))
print(ans)


def need_change(minimum, number, n):
	for i in range(n):
		if int(minimum[i]) > int(number[i]):
			return True
		if int(minimum[i]) < int(number[i]):
			return False
	return False

def ad(number, dnum):
	result = ''
	for item in number:
		result += str((int(item) + dnum) % 10)
	return result
n = int(input())
number = input()
result = number
for i in range(10):
	new = ad(number, i)
	for j in range(n):
		newnew = new[j:] + new[:j]
		if need_change(result, newnew, n):
			result = newnew
print(result)


import sys

def try_combination(num_digits, number, index):
	rotated = number[index:] + number[:index]
	diff = rotated[0] * num_digits
	result = ''
	for ch1 in rotated:
		result += str((int(ch1) + (10 - int(rotated[0]))) % 10)
	return result
num_digits = int(input(''))
number = input('')
min_val = int(str(9) * num_digits)
for i in range(num_digits):
	cur_val = try_combination(num_digits, number, i)
	min_val = min(min_val, int(cur_val))
print(('{:0' + str(num_digits) + '}').format(min_val))


__author__ = 'Rakshak.R.Hegde'
n = int(input())
digits = list(map(int, input()))
enum = [[0] * n for i in range(10)]
enum[0] = digits
for i in range(1, 10):
	for j in range(n):
		enum[i][j] = (enum[i - 1][j] + 1) % 10
comp = []
for i in range(10):
	if enum[i][0] == 0:
		comp.append(enum[i])
	for j in range(1, n):
		if enum[i][j] == 0 and enum[i][j - 1] != 0:
			comp.append(enum[i][j:] + enum[i][:j])
print(''.join(map(str, min(comp))))


n = int(input())
s = [int(x) for x in input()]
min = [9] * n
minK = -1
for i in range(n):
	cur = [(x + 10 - s[i]) % 10 for x in s[i:] + s[:i]]
	if cur < min:
		min = cur
		minK = i
cur = [(x + 10 - s[minK]) % 10 for x in s[minK:] + s[:minK]]
print(''.join(map(str, cur)))


n = int(input())
initial = input()
minString = initial
for i in range(n):
	initial = initial[n - 1] + initial[:n - 1]
	converted = ''
	for j in range(n):
		converted += str((int(initial[j]) - int(initial[0]) + 10) % 10)
	if int(converted) < int(minString):
		minString = converted
print(minString)


import sys

def fn(x, string):
	return (x + 10 - string[0]) % 10
num = int(input())
string = input()
string = list(map(int, string))
temp = []
min = [fn(x, string) for x in string]
for i in range(1, num):
	for j in range(i, i + num):
		temp.append((string[j % num] + (10 - string[i])) % 10)
	if min > temp:
		min = temp.copy()
	temp = []
for i in range(0, num):
	sys.stdout.write(str(min[i]))


n = int(input())
num = input()
ans = str(num)
for i in range(n):
	d = int(num[i])
	new_num = ''
	for j in range(n):
		dig = (int(num[(i + j) % n]) - d) % 10
		new_num += str(dig)
	ans = min(ans, new_num)
print(ans)