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

for i in range(m):
    s, c = map(int, input().split())
    if s == 1 and c == 0 and n > 1:
        ans = '-1'
        break
    if a[s-1] == -1:
        a[s-1] = c
    elif a[s-1] == c:
        a[s-1] = c
    else:
        ans = '-1'
        break

if ans == '-1':
    print(ans)
elif a[0] == 0 and n == 1:
    ans = '0'
    print(ans)
elif a[0] == 0:
    ans = '-1'
    print(ans)
else:
    ans = ''
    if a[0] == -1:
        a[0] = 1
    for k in range(n):
        ans = ans + str(a[k])
    print(ans)