import math
N, M = map(int,input().split())
sc = [list(map(int,input().split())) for _ in range(M)]
lower = 10**(N-1)
upper = 10**N
if M==0:
    print(0)
    exit()
if N==1:
    lower = 0
for n in range(lower, upper):
    nstr = str(n)
    flg = 0
    for i in range(M):
        if nstr[sc[i][0]-1] != str(sc[i][1]):
            flg = 1
            break
    if flg==0:
        print(n)
        exit()

print(-1)
