n, m = map(int, input().split())
a, b, num = [0]*n, [0]*n, [0]*n
num[0]=1
for i in range(m):
  a[i], b[i] = map(int, input().split())
  num[a[i]-1]=b[i]
for i in range(m):
  if num[a[i]-1]!=b[i]:
    print(-1)
    exit()

ans=''
for i in num:
  ans+=str(i)
ans = int(ans)
ans = str(ans)
if len(ans)==n:
  print(ans)
else:
  print(-1)