n,m = map(int,input().split())
sc = [0]*m
for i in range(m):
    sc[i] = list(map(int,input().split()))
ans = 1
keta = [0] + [-1]*n
for i in range(m):
    if keta[sc[i][0]] == -1:
        keta[sc[i][0]] = sc[i][1]
    elif keta[sc[i][0]] == sc[i][1]:
        pass
    else:
        ans = -1
if keta[1] == 0:
    ans = -1
if ans == -1:
    print(-1)
else:
    for i in range(1,n+1):
        if keta[i] == -1:
            print(0,end="")
        else:
            print(keta[i],end="")
    print("")