# C
N,M=map(int,input().split())
cnd=[tuple(int(i) for i in input().split()) for j in range(M)]
ans=-1
for n in range(10**N-1):
    # print(n)
    flag=True
    n_str=str(n)
    for s,c in cnd:
        if n_str[s-1]!=str(c):
            # print(n_str[s-1],c)
            flag=False
            break
    if flag:
        ans=n
        break
print(ans)