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