n,m = map(int, input().split())
sc = [list(map(int, input().split())) for _ in range(m)]
for i in range(1000):
    num = str(i)
    if len(num) == n and all(num[s-1]==str(c) for s,c in sc):
        print(i)
        break
else:
    print(-1) 