import sys
n, m = map(int, input().split())
c = [list(map(int, input().split())) for i in range(m)]

if n > 1:
    for i in range(m):
        if c[i][0] == 1 and c[i][1] == 0:
            print(-1)
            sys.exit()
    
for i in range(m):
    for j in range(m):
        if c[i][0] == c[j][0] and c[i][1] != c[j][1]:
            print(-1)
            sys.exit()


c1 = 0 
c2 = 0
c3 = 0

for i in range(m):
    if c[i][0] == 1:
        c1 = c[i][1]
    elif c[i][0] == 2:
        c2 = c[i][1]
    elif c[i][0] == 3:
        c3 = c[i][1]
    
if n == 1:
    print(c1)
elif n == 2:
    print(c1 * 10 + c2)
elif n ==3:
    if c1 == 0:
        c1 = 1
    print(c1 * 100 + c2 * 10 + c3)