n, m=map(int, input().split())
a = [-1]*n
ans = 0
for i in range(m):
  s, c = map(int, input().split())
  if a[s-1]!=c and a[s-1]!=-1:
    ans = -1
    break
  elif n>1 and s==1 and c==0:
    ans = -1
    break
  else:
    a[s-1]=c
if ans == 0:
  for i in range(n):
    if a[n-1-i] != -1:
      ans += a[n-1-i]*10**i
print(ans)