N, M = map(int, input().split())  #数字
S = [list(map(int, input().split())) for i in range(M)]  #数字、複数行複数列

A = [0] * N

for i, j in S:
    if i - 1 == 0 and j == 0:
        print(-1)
        exit()    
    elif A[i-1] == 0 or A[i-1] == j:
        A[i - 1] = j
    else:
        print(-1)
        exit()

if A[0] == 0:
    A[0] = 1
else:
    A = [str(i) for i in A]
    print(''.join(A))#間隔なし