n,m=map(int,input().split())
s=[0]*(m+1)
c=[0]*(m+1)
d=[-1]*(m+1)

def set_d(k,j):
  if d[k]==-1 or d[k]==j:
    d[k]=j
    return True
  else:
    return False
def fill_0():
  for i in range(1,m+1):
    if d[i]==-1:
      d[i]=0

def min_d(d):
  s=0
  for i in range(1,m+1):
     if d[i]!=-1:
        s=s*10+d[i]
  return s if s>0 else -1
 
def check():  
  for i in range(1,m+1):
      *sc,=map(int,input().split())
      s[i],c[i]=sc[0],sc[1]
      if not set_d(s[i],c[i]):
          print(-1)
          return False
  fill_0()
  print(min_d(d))

check()  