N, M = list(map(int,input().split()))
S = [list(map(int,input().split())) for i in range(M)]
#print(S)

ans = 0
A = [0] * N

for i in range(M):
    if A[S[i][0]-1] == 0 :
        A[S[i][0]-1] = S[i][1]
    else:
        ans = -1

if ans == -1 or len(S) == 1:
    print('-1')
else:
    s = ''.join([str(n) for n in A[::-1]])
    print(s)