N,M = map(int,input().split())
sl = []
cl = []
for i in range(M):
    s,c = map(int,input().split())
    s -= 1
    sl.append(s)
    cl.append(c)
for i in range(1000):
    digit = list(str(i))
    if len(digit) != N:
        continue
    flag = True

    for j in range(M):
        print(sl[j])
        print(digit[sl[j]])
        if int(digit[sl[j]]) != cl[j]:
            flag = False
    if flag:
        print(i)
        exit()
print(-1)