n, m = [int(i) for i in input().split()]
sc = [[int(i) for i in input().split()] for j in range(m)]

for i in range(900):
    result = True
    num = str(100 + i)
    for j in range(m):
        s, c = sc[j]
        if not num[s - 1] == c:
            result = False
            break
    if(result):
        print(int(num))
        exit()
print(-1)
