N, M = map(int, input().split())
s, c = [0]*M, [0]*M
for i in range(0, M):
    s[i], c[i] = map(int, input().split())
a = [0]*N
for i in range(0, M):
    a[s[i]-1] = c[i]
for i in range(0, M):
    for j in range(i, M):
        if (s[i] == s[j] and c[i] != c[j]) or (s[i] == 1 and c[i] == 0):
            print (-1)
            break
    else:
        continue
    break
else:
    if a[0] == 0:
        a[0] = 1
    map_res = map(str, a)
    res = "".join(map_res)
    print (res)