N, M = map(int, input().split())
data = [list(map(int, input().split())) for _ in range(M)]
for i in range(1,1000):
    t = str(i)
    if len(t) != N:
        continue
    flg = True
    for item in data:
        if t[item[0]-1] != str(item[1]):
            flg = False
            break
    if flg:
        print(i)
        exit()
print(-1)