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 (flag == True):
  print(-1)
else:
  if (lst[0] == 10**9):
    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 (lst[0] == 0):
      if (N==1):
        print(0)
      else:
        print(-1)
    else:
      for i in range(N):
        if (lst[i] == 10**9):
          lst[i] = 0
      str_lst = list((map(str,lst)))
      print(''.join(str_lst))
