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

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

print(l)
f = 0
con = ""

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

if f:
    print(-1)
else:
    for i in range(n):
        con += str(l[i][0])
    print(int(con))