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 = [0] * N
for i in range(M):
    if ans[S[i] - 1] != 0 and ans[S[i] - 1] != C[i]:
        print(-1)
        exit()
    ans[S[i]-1] = C[i]


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