N,M = map(int,input().split())
k = ["F"]*N
flag_2 = 0
flag_3 = 0
for i in range(M):
    s,c = map(int,input().split())
    if k[s-1] == "F":
        k[s-1] = str(c)
    else:
        if str(c) != k[s-1]:
            k[s-1] = "?"
for i in range(len(k)):
    if k[i] == "?":
        flag_3 += 1
        break
if flag_3 == 1:
    print(-1)
else:
    for i in range(10**(N-1),10**(N)):
        p = str(i)
        flag = 0
        for j in range(N):
            if k[j] == "F":
                continue
            else:
                if p[j] == k[j]:
                    continue
                else:
                    flag += 1
                    break
        if flag == 0:
            print(i)
            flag_2 += 1
            break
    if flag_2 == 0:
        print(-1)