n, m = map(int, input().split())
if m == 0:
    print([1, 10, 100][~-n])
    exit()
x = []
y = []
z = []
for _ in range(m):
    s, c = map(int, input().split())
    if s == 1:
        x.append(c)
    elif s == 2:
        y.append(c)
    else:
        z.append(c)
if n == 1:
    if len(set(x)) > 1:
        print(-1)
    elif len(set(x)) < 1:
        print(1)
    elif x[0] == 0:
        print(-1)
    else:
        print(x[0])
elif n == 2:
    if len(set(x)) > 1 or len(set(y)) > 1:
        print(-1)
        exit()
    if len(set(x)) == 1 and x[0] == 0:
        print(-1)
        exit()
    if len(set(x)) == 0:
        a = 1
    else:
        a = x[0]
    if len(set(y)) == 0:
        b = 0
    else:
        b = y[0]
    print(a, b, sep='')
else:
    if len(set(x)) > 1 or len(set(y)) > 1 or len(set(z)) > 1:
        print(-1)
        exit()
    if len(set(x)) == 1 and x[0] == 0:
        print(-1)
        exit()
    if len(set(x)) == 0:
        a = 1
    else:
        a = x[0]
    if len(set(y)) == 0:
        b = 0
    else:
        b = y[0]
    if len(set(z)) == 0:
        c = 0
    else:
        c = z[0]
    print(a, b, c, sep='')
