N,M = map(int,input().split())
lst = [10**9] * N
flag = False
for i in range(M):
  s,c = map(int,input().split())
  if (lst[s-1] == 10**9):
    lst[s-1] = c
  else:
    if (lst[s-1] != c):
      flag = True
      break
      
if (lst[0] != 10**9 and flag == False and lst[0] != 0):
  for i in range(N):
    if (lst[i] == 10**9):
      lst[i] = 0
  str_lst = list((map(str,lst)))
  print(''.join(str_lst))
elif (lst[0] == 10**9 and flag == False):
  lst[0] = 1
  for i in range(1,N):
    if (lst[i] == 10**9):
      lst[i] = 0
  str_lst = list((map(str,lst)))
  print(''.join(str_lst))
else:
  if (N == 1 and lst[0] == 0 and flag == False):
    print(0)
  else:
    print(-1)