N, M = map(int,input().split())
A = [list(map(int,input().split())) for _ in range(M)]

b = [0]*N

ans = 0
for i in range(N):
    if b[A[i][0]-1] ==0:
        b[A[i][0]-1] = A[i][1]
    elif b[A[i][0]-1] == A[i][1]:
        pass
    else:
        ans = -1
        break

s = ''.join([str(N) for N in b])

if ans == 0:
    print(s)
else:
    print(ans)