N,M = map(int,input().split())
sc = [0]*M
for i in range(M):
    sc[i] = list(map(int, input().split()))
ans = [0]*N
l = []
ansa = ""

if M == 0:
    ansa = "1"
    for i in range(N-1):
        ansa += "0"
    print(ansa)
    exit()

for s, c in sc:
    if s in l and ans[s-1] != c:
        print("-1")
        exit()
    if len(ans) >= s:
        ans[s-1] = c
        l.append(s)
    else:
        print("-1")
        exit()

if 0 == ans[0] and len(ans) > 1:
    print("-1")
    exit()

print(''.join(map(str,ans)))