n, m = list(map(int, input().split()))
sc = [input().split() for _ in range(m)]
for i in range(1000):
    a = str(i)
    if len(a) != n: continue
    for j in range(m):
        if a[int(sc[j][0])-1] != sc[j][1]: break
        if j == m-1:
            print(i)
            exit()
print(-1)
