n, m = map(int, input().split())
ans = [0] * n

no_ans = False

for i in range(m):
    s, c = map(int, input().split())
    if ans[s-1] == 0:
        ans[s-1] = c
    elif ans[s-1] != c:
        no_ans = True

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