n, m = map(int, input().split())
l = [list(input().split()) for i in range(m)]
for num in range(1000):
    for i in range(m):
        if len(str(num)) < n:
            break
        if str(num)[int(l[i][0])-1] != l[i][1]:
            break
    else:
        print(num)
        exit()
print(-1)