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

num = [0]*3

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

if num[0] == 0:
    if not n <= 2:
        print(-1)
        exit()
    if num[1] == 0:
        if n != 1:
            print(-1)
            exit()

print("".join(map(str,num)))