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