n,m=map(int,input().split())
ans =[-1]*5
for _ in range(m):
    s,c = map(int,input().split())
    if ans[s] == -1 or ans[s] == c:
        ans[s] = c
    else:
        print(-1)
        exit()

for i in range(5):
    if ans[i] == -1:
        ans[i] = 0

res = 0
cnt = 0
for i in range(4,-1,-1):
    if cnt ==0 and ans[i] == 0:
        continue
    res += ans[i] * 10 ** cnt
    cnt += 1

keta = 0
tmp = res
while(res):
    res//=10
    keta +=1
if n != keta:
    print(-1)
else:
    print(tmp)