N, M = [int(x) for x in input().split()]
t = [[] for i in range(N)]
for i in range(M):
  a,b = [int(x) for x in input().split()]
  t[a-1].append(b)
for i in range(len(t)):
  if len(list(set(t[i])))>1:
    print(-1)
    exit()
  elif t[i] == []:
    t[i].append(0)
#print(t)
num = str()
for i in t:
  num += str(i[0])
num = int(num)
if len(str(num)) == N:
  print(num)
else:
  print(-1)