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

num = [-1 for _ in range(n)]

for _ in range(m):
    i, x = map(int, input().split())
    i -= 1
    if i > n-1:
        print(-1)
        exit()
    elif n > 1 and x == 0:
        print(-1)
        exit()
    elif num[i] == -1:
        num[i] = x
    elif num[i] != x:
        print(-1)
        exit()
    
if num[0] == -1:
    num[0] = 1

ans = ""
for n in num:
    if n == -1:
        ans += str(0)
    else:
        ans += str(n)
print(ans)
