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

l = [[0 for _ in range(2)] for _ in range(n)]

f = 0
f2 = 0
con = ""

for i in range(m):
    s, c = map(int,input().split())
    if l[s-1][1] == 1 and l[s-1][0] != c:
        f = 1
    elif s == 1 and c == 0 and n != 1:
        f = 1
    else:
        l[s-1][0] = c
        l[s-1][1] = 1

for i in range(n):
    if l[i][0] == 0 and f2 == 0 and n != 1:
        f = 1
    else:
        f2 = 1
        con += str(l[i][0])

if f:
    print(-1)
else:
    print(int(con))
    
