lst = []

for i in range(10):
    for j in range(10):
        for k in range(10):
            lst.append(str(i)+str(j)+str(k))

N, M = map(int, input().split())
S = []
C = []
for l in range(M):
    S.append(0)
    C.append(0)
    S[l], C[l] = map(int, input().split())
    C[l] = str(C[l])

for n in range(1000):
    for m in range(M):
        if lst[n][S[m]-1] != C[m]:
            lst[n] = "1000"
    lst[n] = int(lst[n])

print(min(lst))