n, m = map(int, input().split())
num = [0 for _ in range(n)]
flag = False
for i in range(m):
    s, c = map(int, input().split())
    if s == 1 and c == 0:
        flag = True
    if num[s - 1] == 0:
        num[s - 1] = c
    elif num[s - 1] != c:
        flag = True

else:
    if flag:
        print(-1)
    elif num[0] != 0:
        for i in range(n):
            print(num[i], end="")
    else:
        num[0] = 1
        for i in range(n):
            print(num[i], end="")

