N,M=map(int,input().split())
x=[False]*N
flag=0

for _ in range(M):
  a,b=map(str,input().split())
  if a=="1" and b=="0":
    flag=1
  if x[int(a)-1]==False:
    x[int(a)-1]=b
  else:
    if x[int(a)-1]!=b:
      flag=1
if flag==1:
  print("-1")
else:
  for i in range(N):
    if x[i]==False:
      x[i]="0"
  else:
    print("".join(x))
      