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

a = [0]*n

for i in range(m):
    s, c = map(int, input().split())
    if a[s-1] != 0 and a[s-1] != c:
        print(-1)
        exit()
    if n != 1 and a[0] == 0:
        print(-1)
        exit()
    a[s-1] = c
if n != 1 and a[0] == 0:
    a[0] = 1
for i in range(n):
    print(a[i], end="")
