N, M = map(int, input().split())
s_c = [list(map(int, input().split())) for _ in range(M)]
 
if N == 1:
  a, b = 0, 10**N
elif N >= 2:
  a, b = 10**(N-1), 10**N
 
ans = '-1'
for i in range(a, b):
  flag = True
  for j in range(M):
    if str(i)[s_c[j][0]-1] != str(s_c[j][1]):
      flag = False
  if flag:
    ans = i
    break
 
print(ans)



n,m=map(int,input().split())
arr=[list(map(int,input().split())) for _ in range(m)]
if n==1:
  for i in range(10):
    tmp=str(i)
    flag=True
    for j in range(m):
      if tmp[arr[j][0]-1]!=str(arr[j][1]):
        flag=False
    if flag==True:
      print(i)
      break
  else:
    print(-1)
else:
  for i in range(10**(n-1),10**n):
    tmp=str(i)
    flag=True
    for j in range(m):
      if tmp[arr[j][0]-1]!=str(arr[j][1]):
        flag=False
    if flag==True:
      print(i)
      break
  else:
    print(-1)