#coding:utf-8
n, m = map(int, input().split())
num = '0' * n
count = [0, 0, 0]


for i in range(m):
    s, c = map(int, input().split())
    #print(num, count)
    if (n >= 2 and s == 1 and c == 0) or (count[s-1] >= 1 and int(num[s-1]) != c):
        print(-1)
        exit()
    else:
        count[s-1] += 1
        if int(num[s-1]) != c:
            #num = num.replace(num[s-1], str(c), 1)
            num = list(num)
            num[s-1:s] = str(c)
            num = ''.join(num)

print(num)
