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

ans=["0"]*n
for i in s_c:
    ans[int(i[0])-1]=i[1]

if m>1:
    for i in range(m-1):
        for k in range(i+1,m):
            if s_c[i][0]==s_c[k][0] and s_c[i][1]!=s_c[k][1]:
                ans = -1
                break

if n>1:
    if ["1","0"] in s_c:
        ans = -1
    if ans[0]=="0":
        ans=-1

print(int("".join(ans)) if ans != -1 else -1)