n,m=map(int,input().split())
x=9999999999999999
s=[list(map(int,input().split())) for i in range(m)]
s=sorted(s)
for i in range(m):
  if s[i][0]==1 and s[i][1]==0:
    x=-1

for i in range(m):
  for j in range(m):
    if s[i][0]==s[j][0] and s[i][1]!=s[j][1]:
      x=-1

a=[0]*n
ans=0
for i in range(n):
  a[s[i][0]-1]=s[i][1]

if a[0]==0:
  a[0]=1

for i in range(m):
  ans+=a[i]*10**(n-i-1)


print(min(x,ans))