n, m = map(int, input().split())
table = [tuple(map(int, input().split())) for _ in range(m)]
num = [-1] * 3
for s, c in table:
    if num[s-1] != -1 and num[s-1] != c:
        print(-1)
        exit()
    num[s-1] = c
if num[0] == 0 or (num[0] == -1 and num[1] == 0):
    print(-1)
    exit()
if num[0] == -1 and num[1] == -1 and num[2] != -1:
    print(num[2])
    exit()
if num[0] != -1:
    num[1] = num[1] if num[1] != -1 else 0
    num[2] = num[2] if num[2] != -1 else 0
    num = map(str, num)
    print("".join(num))
    exit()
if num[0] == -1 and num[1] != -1:
    num[2] = num[2] if num[2] != -1 else 0
    num = map(str, num)
    print("".join(num))
    exit()