N, M = map(int, input().split())

ans = ['*'] * N
flag = 0
for i in range(M):
  s, c = map(int, input().split())
  if ans[s-1]=='*' or ans[s-1]==str(c):
    ans[s-1] = str(c)
  else:
    flag = 1
    break;

if flag == 0:
  num = ['0' if i == '*' else i for i in ans]
  an = ''.join(num)
  if len(an)!=1 and an[0]=='0':
    flag = 1
  
if flag == 1:
  an = -1
  
print(int(an))