n,m = map(int, input().split())
lis = []
for i in range(m):
    lis.append(list(map(int, input().split())))
    
a = [0]*3

for i in lis:
    a[i[0]-1] = i[1]

s = ""
for k in a:
    s += str(k)
    
s1 = int(s)
s2 = str(s1)


if len(s2) != n:
    print("-1")
else:
    print(int(s))

