n,m = map(int,input().split())
s = [0]*m
c = [0]*m
for i in range(m):
  s[i],c[i] = map(int,input().split())
ans = [0]*n
ans[0] = 1

flag = 0

if n == 1:
  for i in range(m-1):
    if c[0]!=c[i+1]:
      flag=-1
      break
  if flag == 0:
    print(c[0])
  else: 
    print(-1)
      
if n == 2:
  for i in range(m):
    ans[s[i]-1]=c[i]
  for i in range(m):
    if ans[s[i]-1]!=c[i]:
      flag=-1
      break
  if ans[0] == 0:
    print(-1)
  elif flag == 0:
    print(ans[0]*10+ans[1])
  else: 
    print(-1)

if n == 3:
  for i in range(m):
    ans[s[i]-1]=c[i]
  for i in range(m):
    if ans[s[i]-1]!=c[i]:
      flag=-1
      break
  if ans[0]==0:
    print(-1)
  elif flag == 0:
    print(ans[0]*100+ans[1]*10+ans[2])
  else: 
    print(-1)