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

sc.sort(key=lambda x: x[0],reverse=True)
n = len(sc)
for i in range(1,1000):
    i = str(i)
    if len(i) < sc[0][0]:
        continue
    c = n
    for j in range(m):
        if i[sc[j][0]-1] == str(sc[j][1]):
            c -= 1
    if c == 0:
        print(i)
        quit()

print(-1)