N,M = map(int,input().split())
l = [list(map(int,input().split())) for _ in range(M)]

num = ["0"]*N

for i in l:
    num[i[0]-1] = str(i[1])
    
ans = "".join(num)

for i in l:
    if i[0] == 1 and i[1] == 0:
        print(-1)
        exit()
    if ans[i[0]-1] != str(i[1]):
        print(-1)
        exit()
if N !=len(str(int((ans)))):
    if N == 3:
        ans = int(ans)+100
    if N == 2:
        ans = int(ans)+10
print(int(ans))