n, m = map(int, input().split())
if m == 0:
    print(n)

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

if n == 1:
    if L[0] == -1:
        print(0)
        exit()
    else:
        print(L[0])
        exit()

ans = ''
for i in range(n):
    if i == 0:
        if L[i] == 0:
            print(-1)
            exit()
        elif L[i] == -1:
            ans += '1'
        else:
            ans += str(L[i])
    else:
        if L[i] == -1:
            ans += '0'
        else:
            ans += str(L[i])
print(ans)