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

if n == 1:
    s = "0"
elif n == 2:
    s = "10"
else:
    s = "100"

flag = 0
chk = [-1] * n

for _ in range(m):
    a, b = map(int, input().split())

    if s[a - 1] != '0':
        if s[a - 1] != str(b):
            flag = 1

    if n > 1 and a == 1 and b == 0:
        flag = 1

    if chk[a - 1] > -1 and chk[a - 1] != b:
        flag = 1

    chk[a - 1] = int(b)
    s = s[:a-1] + str(b) + s[a:]

if flag == 0:
    if n == 1:
        print(s)
    elif int(s) >= 10 ** (n - 1):
        print(s)
    else:
        print(-1)
else:
    print(-1)