import sys
N, M = map(int, input().split())

ans = [0]*N
ans1 = [0]*N
for _ in range(M):
    a, b = map(int, input().split())
    if ans[a-1] != 0 and ans[a-1] != b:
        ans[a-1] = -1
    elif ans[a-1] == 0:
        ans[a-1] = b
        ans1[a-1] = 1
    print(ans)

if -1 in ans:
    print('-1')
elif (sum(ans) == 0 and ans1[-1] == 1) or (N == 1 and M == 0):
    print('0')
else:
    b = ''.join([str(i) for i in ans])
    if N == len(str(int(b))):
        print(int(b))
    else:
        for i, j in enumerate(ans):
            if i == N - len(str(int(b))):
                print(int(b))
                sys.exit()
            if ans1[i] == 1:
                print('-1')
                sys.exit()
    
