n, m = map(int, input().split())
sList = []
pList = []
for i in range(m):
  s, p = map(int, input().split())
  if s == 1 and p == 0:
    print(-1)
    exit()
  existFlag = False
  for i, sListItem in enumerate(sList):
    if sListItem == s and pList[i] != p:
      print(-1)
      exit()
    if s in sList:
      existFlag = True
  if not existFlag:
    sList.append(s)
    pList.append(p)

result = ['0'] * n
for i, s in enumerate(sList):
  result[s-1] = str(pList[i])
if result[0] == '0':
  result[0] = '1'
print(''.join(result))
