N, M = map(int, input().split())
sc = set([tuple(map(int, input().split())) for i in range(M)])

if M == 0:
    if N == 1:
        print(0)
    elif N == 2:
        print(10)
    else:
        print(100)

for i in sc:
    for j in sc:
        if i[0] == j[0] and i[1] != j[1]:
            print(-1)
            exit()

for i in sc:
    if i[0] == 1 and i[1] == 0:
        print(-1)
        exit()
    if i[0] > N:
        print(-1)
        exit()
ans = ""
for i in sc:
    if i[0] == 1:
        ans = str(i[1])
if N == 1:
    print(ans)
    exit()

if len(ans) < 1:
    ans = "1"

for i in sc:
    if i[0] == 2:
        ans += str(i[1])
if len(ans) < 2:
    ans += "0"
if N == 2:
    print(ans)
    exit()

for i in sc:
    if i[0] == 3:
        ans += str(i[1])
if len(ans) < 3:
    ans += "0"
print(ans)