N, M = input().split()
N = int(N)
M = int(M)
S = []
C = []
A = []
zero_flag = False
for m in range(M):
  s, c = input().split()
  s = int(s)
  c = int(c)
  S.append(s)
  C.append(c)
  A.append((10**(N-(s-1)-1)) * c)
  if s == 1 and c == 0 and N != 1:
    zero_flag = True

flag = False
for a1 in A:
  for a2 in A:
    if a1 != a2 and len(str(a1)) == len(str(a2)):
      if a1 != a2:
        flag = True
  
if zero_flag:
  print('-1')
elif flag:
  print('-1')
else:
  ans = sum(list(set(A)))
  print(ans)
