N, M = map(int, input().split())
A_list = []
dic_A = {}
flag = True
for i in range(M):
    A = list(map(int, input().split()))
    if A[0] in dic_A:
        if dic_A[A[0]]!=A[1]:
            flag = False
    else:
        dic_A[A[0]] = A[1]
    A_list.append(A)
for i in range(M):
    if A_list[i][0]==1 and A_list[i][1]==0:
        flag = False
if flag == False:
    print(-1)
else:
    ans = []
    cnt = 1
    for i, v in sorted(dic_A.items()):
        if cnt==N+1:
            break
        if cnt!=i:
            while(cnt!=i):
                ans.append(str(0))
                cnt+=1
        v = str(v)
        ans.append(v)
        cnt+=1
    print(int("".join(ans)))