n, m = map(int, input().split())

num = [0]*3
flag = [0]*3

for i in range(m):
    s, c = map(int, input().split())
    if num[s-1] == c or (num[s-1] == 0 and flag[s-1] == 0):
        num[s-1] = c
        flag[s-1] = 1
    else:
        print(-1)
        exit()

if num[0] == 0:
    num = num[1:]
    if num[0] == 0:
        num = num[1:]

if len(num) == n:
    print("".join(list(map(str, num))))
else:
    print(-1)
