n, m = map(int,input().split())
a = [10 for x in range(n)]
for _ in range(m):
    s, c = map(int, input().split())
    if c < a[s-1]:
        a[s-1] = c

strn = ""
if a[0] == 10:
    print(-1)
else:
    if a[0] == 0 and len(a) != 1:
        print(-1)
    else:
        for x in a:
            strn += str(0) if x==10 else str(x)
        print(int(strn))
        
print("\n")
