n, m = map(int, input().split())
list_1 = []
for i in range(m):
  s, c = input().split()
  list_1.append([int(s), int(c)])

# -1の条件
for k in range(m):
  if n == 1 and list_1[k][0] == 1 and list_1[k][1] == 0:
    print(0)
    exit(0)
  elif list_1[k][0] == 1 and list_1[k][1] == 0:
    print(-1)
    exit(0)
    
def check(x):
  if x >= m:
    return
  for j in range(m-x):
    if list_1[j][0] == list_1[j+1][0]:
      if list_1[j][1] != list_1[j+1][1]:
        print(-1)
        exit(0)
  check(x+1)

check(1)
  
# 数作成
if n == 1:
  for _ in range(m):
    print(list_1[_][1])
elif n == 2:
  num = list('10')
  for _ in range(m):
    num[list_1[_][0]-1] = str(list_1[_][1])
  print("".join(num))
else:
  num = list('100')
  for _ in range(m):
    num[list_1[_][0]-1] = str(list_1[_][1])
  print("".join(num))