def get_unique_list(seq):
    seen = []
    return [x for x in seq if x not in seen and not seen.append(x)]

N,M=map(int,input().split())
a=[]
b=[]
A=0
for i in range(M):
    a.append(list(map(int,input().split())))
    b.append(a[i][0])

aa=get_unique_list(a)
if len(set(b))!=len(aa):
    ans=-1

else:
    for j in range(len(aa)):
      A+=aa[j][1]*(10**(N-aa[j][0]))
      ans=A
if N!=len(str(ans)):
    ans=-1
print(ans)