n,m = map(int,input().split())
s_c = []
for x in range(m):
    s_c.append(list(map(int,input().split())))
    
ans = [0 for x in range(n)]
ch = []
flag = 0
for x in s_c:
    if (n!=1)&(x[0]==1)&(x[1]==0):
        print(-1)
        flag = 1
        break
    if x in ch:
        continue
    else:
        ch.append(x)
        if ans[x[0]-1]==0:
            ans[x[0]-1] = x[1]
        else:
            print(-1)
            flag = 1
            break
if flag == 0:
    if ans[0] == 0:
        print(-1)
    else:
        print("".join(map(str,ans)))