from sys import stdin
n,m = map(int,stdin.readline().rstrip().split())
li = [list(map(int,stdin.readline().rstrip().split())) for _ in range(m)]
for i in range(1000):
    s = str(i)
    flag = True
    for j,k in li:
        if j > len(s):
            flag = False
            break
        if s[j-1] != str(k):
            flag = False
    if flag:
        print(s)
        exit()
print(-1)