N,M=map(int,input().split())
s=[]
c=[]
for i in range(M):
 
    a, b = map(int,input().split())
    s.append(a)
    c.append(b)
 
okflag = True
 
 
for i in range(M):
 
 
    if not okflag:
         break
    for j in range(M):
     if not okflag:
         break
     if not (i==j):
 
        if s[i]==s[j] and c[i]!=c[j]:
 
            okflag = False
            print("-1")
 
if okflag:
    answer = ["0"] * N
    for i in range(M):
        answer[s[i]-1] = str(c[i])
    if not N == 1 and answer[0] == "0":
        answer[0] = "1"
    result = ''.join(answer)
    print(result)