N,M=map(int,input().split())
s=[]
c=[]
for _ in range(M):
    S,C=map(int,input().split())
    s.append(S)
    c.append(C)

num=[0]*N

for i in range(M):
    if num[s[i]-1]==0:
        num[s[i]-1]=c[i]
    elif num[s[i]-1]!=0 and num[s[i]-1]!=c[i]:
        num="-1"
if num[0]==0:
    num="-1"
if num=="-1":
    print(num)
else:
    for j in range(N):
        print(num[j],end="")