n, m = map(int, input().split())
num = [10]*n
no = 0

for i in range(m):
    s, c = map(int, input().split())
    if num[s-1]==10 or num[s-1]==c:
        num[s-1] = c
    elif num[s-1]!=10 and num[s-1]!=c:
        no = 1

if no == 1:
    print(-1)
elif num[0]==10 or num[0]==0:
    print(-1)
else:
    for i in range(n):
        if num[i] == 10:
            num[i] = 0
    if n == 1:
        print(num[0])
    elif n == 2:
        print(num[0]*10+num[1])
    else:
        print(num[0]*100+num[1]*10+num[2])