import numpy as np

n, m = list(map(int, input().split()))
a = [list(map(int, input().split())) for i in range(m)]
b = ["0" for i in range(n)]
frag = False
for i in a:
    if b[i[0]-1] == "0" or b[i[0]-1] == str(i[1]):
        b[i[0]-1] = str(i[1])
    else:
        frag = True
num = "".join(b)
if frag is False:
    if len(str(int(num))) == len(num):
        print(num)
    else:
        print(-1)
else:
    print(-1)