nn,m=map(int,input().split())
sc=[list(map(int,input().split())) for _ in range(m)]
def check(n):
    ss = str(n)
    if len(ss)!=nn:return False
    for s,c in sc:
        if ss[s-1]!=str(c): return False
    return True
for i in range(1000):
    if check(i):print(i);exit()
print(-1)