N, M = map(int, input().split())
a = [[] for _ in range(N)]
for i in range(M):
  s, c = map(int, input().split())
  a[s-1].append(c)
flag = 0
ans = [0]*N
for i in range(len(a)):
  if len(set(a[i]))>1:
    flag = 1
    break
  elif a[i]:
    ans[i] = a[i][0]
if a[0]:
  if a[0][0] == 0:
    flag = 1
    
if flag == 0:
  if ans[0] == 0:
    ans[0] = 1
  ans = ''.join((str(n) for n in ans))
  print(int(ans))
else:
  print(-1)