n, m = map(int, input().split())
num = []
for _ in range(m):
    num.append(list(map(int, input().split())))

h = []
t = []
o = []
for i in range(len(num)):
  if num[i][0] == 1:
    h.append(num[i][1] * 100)
  if num[i][0] == 2:
    t.append(num[i][1] * 10)
  if num[i][0] == 3:
    o.append(num[i][1])

guess_num = min(h, default=0) + min(t, default=0) + min(o, default=0)
if guess_num in range(1, 1000):
	print(guess_num)