N,M = map(int,input().split())
S_C = list([str(input()) for _ in range(M)])
s,c = 0,0
s_m=[]
c_m=[]
#配列化
for m in range(M):
    s,c = S_C[m].split()
    s_m.append(int(s))
    c_m.append(int(c))
    if int(s) == 1 and int(c)==0:
        print(-1)
        exit()

#チェックコード
ans = [-1] * N
res=0
for i in range(M):
    if ans[s_m[i]-1] == -1:
        ans[s_m[i]-1] = c_m[i]
    else:
        if ans[s_m[i]-1] != c_m[i]:
            print(-1)
            exit()

for i in range(N):
    if ans[i] == -1:
        ans[i] = 0
    res += ans[i]*(10**(N-(i+1)))

print(res)