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

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

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