n, m = map(int, input().split())

# 初期値の作成
ans = ['0'] * n

flag = False
# すり替え
for i in range(m):
  s, c = map(int, input().split())
  if (ans[s-1] == 0):
  	ans[s-1] = str(c)
  else:
    if (ans[s-1] != str(c)):
      flag = True

if (flag == True):
  print('-1')
else:
  ans = "".join(ans)
  if (ans[0] == '0'):
    print('-1')
  else:
    print(ans)