N, M = map(int, input().split())
S = []
C = []
for m in range(M):
    s, c = map(int, input().split())
    S.append(s)
    C.append(c)
cnt = -1
man = False
for n in range(1000):
    num = str(n)
    res = True
    for m in range(M):
        if len(num) != N:
            res = False
            continue
        if num[S[m]-1] != str(C[m]):
            res = False
    if res:
        cnt = int(num)
        man = True
        break
if man:
    print(cnt)
else:
    print(cnt)