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

if a[0] == -1:
    a[0] = 1
for i in range(1, n):
    if a[i] == -1:
        a[i] = 0
ans = 0
for i in a:
    ans = ans * 10 + i
print(ans)
