# ABC 157 C
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)
if not len(set(S)) == len(set(C)) or C[S.index(1)]==0:
    print(-1)
    exit()
ans = 0
for i in range(1,N+1):
    keta =N-i
    if i in set(S):
        ind = S.index(i)
        v = C[ind]
        ans += v*(10**keta)
if len(str(ans)) != N:
    ans+=10**(N-1)
print(ans)