import sys
n,m=map(int,input().split())
sc=[]
ans=dict()
for _ in range(m):
    s,c=map(int,input().split())
    
    if not s in ans.keys():
        ans[s]=c
    else:
        if ans[s] != c:
            print(-1)
            sys.exit()
s=[]
for i in range(1,n+1):
    if i in ans.keys():
        s.append(str(ans[i]))
    else:
        s.append("0")
if s[0] == "0":
    print(-1)
    sys.exit()
else:
    print("".join(s))