N,M = list(map(int,input().split(' ')))
s = []
c = []
for i in range(M):
    S,C = list(map(int,input().split(' ')))
    s.append(S)
    c.append(C)

number = [0,0,0]

f=True

for S,C in zip(s,c):
    if number[N-S]==0:
        number[N-S]=C
    elif number[N-S]==C:
        continue
    else:
        f = False
        break
ans=0
for i in range(N):
    ans+=number[i]*(10**i)

if f:
    if N!=1 and ans==0:
        print(-1)
    else:
        print(ans)
else:
    print(-1)