N, M = map(int, input().split())
sc = []
for i in range(M):
    sp, cp = map(int, input().split())
    sc.append((sp, cp))

ans = 10000

for i in range(10 * N):
    num = str(i)
    flag = True
    for pair in sc:
        if (num[pair[0] - 1] != pair[1]) or len(num) < pair[0]:
            flag = False
            break
    if flag:
        ans = min(ans, i)

if ans == 10000:
    ans = -1
print(ans)