N,M = [int(i) for i in input().split()]
S = []
C = []

for i in range(M):
   s,c = [int(i) for i in input().split()]
   S.append(s)
   C.append(c)

ans = [-1] * N
for i in range(M):
    if ans[S[i] - 1] != -1 and ans[S[i] - 1] != C[i]:
        print(-1)
        exit()
    elif S[i] - 1 == 0 and C[i] == 0:
        print(-1)
        exit()
    ans[S[i]-1] = C[i]

for i in range(N):
    if ans[i] == -1:
        ans[i] = 0

if ans[0] == -1:
    ans[0] = 1
print(''.join(map(str,ans)))