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

    else:
        a[s] = c

if n > 1:
    if a[0] == 0:
        print(-1)
        exit()
    else:
        if a[0] == -1:
            a[0] = 1
        for p in range(len(a)):
            if a[p] == -1:
                a[p] = 0

        for C in a:
            print(C, end='')

else:
    if a[0] == -1:
        print(0)
